meta {
  name: POST craft deny invalid quantity
  type: http
  seq: 4
}

docs {
  NEO-70: non-positive quantity denies with invalid_quantity without consuming inputs.
}

script:pre-request {
  const { ensureItemQuantity, getInventory, sumItemQuantity } = require("./scripts/inventory-api-helper.js");
  await ensureItemQuantity(bru, "scrap_metal_bulk", 5);
  const inventory = await getInventory(bru);
  bru.setVar("scrapBeforeInvalidQuantityDeny", sumItemQuantity(inventory, "scrap_metal_bulk"));
}

post {
  url: {{baseUrl}}/game/players/{{playerId}}/craft
  body: json
  auth: none
}

headers {
  content-type: application/json
}

body:json {
  {
    "schemaVersion": 1,
    "recipeId": "refine_scrap_standard",
    "quantity": 0
  }
}

script:post-response {
  const { getInventory, sumItemQuantity } = require("./scripts/inventory-api-helper.js");
  const inventory = await getInventory(bru);
  bru.setVar("scrapAfterInvalidQuantityDeny", sumItemQuantity(inventory, "scrap_metal_bulk"));
}

tests {
  test("denies with invalid_quantity without consuming scrap", function () {
    expect(res.getStatus()).to.equal(200);
    const body = res.getBody();
    expect(body.schemaVersion).to.equal(1);
    expect(body.success).to.equal(false);
    expect(body.reasonCode).to.equal("invalid_quantity");
    expect(bru.getVar("scrapAfterInvalidQuantityDeny")).to.equal(
      bru.getVar("scrapBeforeInvalidQuantityDeny"),
    );
  });
}
