neon-sprawl/bruno/neon-sprawl-server/perk-state/Post branch select deny bra...

87 lines
2.7 KiB
Plaintext

meta {
name: POST branch select deny branch already chosen
type: http
seq: 4
}
docs {
NEO-48: self-contained deny on fixture player neo48-perk-branch. Pre-request reaches level 2 and picks scrap_efficiency when needed; main request conflicts with bulk_haul.
}
script:pre-request {
const axios = require("axios");
const baseUrl = bru.getEnvVar("baseUrl") || bru.getVar("baseUrl");
const playerId = bru.getEnvVar("neo48PerkBranchPlayerId") || bru.getVar("neo48PerkBranchPlayerId");
const jsonHeaders = { headers: { "Content-Type": "application/json" } };
const progression = await axios.get(
`${baseUrl}/game/players/${playerId}/skill-progression`,
);
const salvage = progression.data?.skills?.find((s) => s.id === "salvage");
const salvageLevel = salvage?.level ?? 1;
if (salvageLevel < 2) {
const grant = await axios.post(
`${baseUrl}/game/players/${playerId}/skill-progression`,
{
schemaVersion: 1,
skillId: "salvage",
amount: 100,
sourceKind: "activity",
},
jsonHeaders,
);
if (grant.status !== 200) {
throw new Error(`salvage grant failed: ${grant.status}`);
}
}
const perkState = await axios.get(`${baseUrl}/game/players/${playerId}/perk-state`);
const salvageTrack = perkState.data?.branchPicks?.find((t) => t.skillId === "salvage");
const hasTier1Pick = Boolean(
salvageTrack?.picks?.some((p) => p.tierIndex === 1),
);
if (!hasTier1Pick) {
const firstPick = await axios.post(
`${baseUrl}/game/players/${playerId}/perk-state`,
{
schemaVersion: 1,
skillId: "salvage",
tierIndex: 1,
branchId: "scrap_efficiency",
},
jsonHeaders,
);
if (firstPick.status !== 200 || firstPick.data?.selected !== true) {
throw new Error(`tier-1 pick failed: ${firstPick.status} ${JSON.stringify(firstPick.data)}`);
}
}
}
post {
url: {{baseUrl}}/game/players/{{neo48PerkBranchPlayerId}}/perk-state
body: json
auth: none
}
body:json {
{
"schemaVersion": 1,
"skillId": "salvage",
"tierIndex": 1,
"branchId": "bulk_haul"
}
}
tests {
test("denies second pick with branch_already_chosen", function () {
expect(res.getStatus()).to.equal(200);
const body = res.getBody();
expect(body.schemaVersion).to.equal(1);
expect(body.selected).to.equal(false);
expect(body.reasonCode).to.equal("branch_already_chosen");
expect(body.unlockedEvents).to.be.an("array").that.is.empty;
const salvage = body.perkState.branchPicks.find((t) => t.skillId === "salvage");
expect(salvage).to.be.an("object");
const pick = salvage.picks.find((p) => p.tierIndex === 1);
expect(pick.branchId).to.equal("scrap_efficiency");
});
}