I am getting an error Assignment#4 in productId

Anyone out there that can help out on this assignment. I am trying to fugure it out but all solutions i tried wont work.Let me know if you need more information about it.

Hey @flight-candidate-665 :wave:t2:

Are you following along with the YouTube video of the course? This fully explains each assignment.

1 Like

Hello there sir and thank you for your reply.Well i am getting the error from Check your solution and not from the API requests. Is it because is missing sort of a test.I tried that too? Any thoughts.This my solution below


Hey @flight-candidate-665 :wave:

This is what I have in place for my solution:

let schema = {
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "default": 1001,
      "examples": [
        1001
      ]
    },
    "category": {
      "type": "string",
      "default": "coffee",
      "examples": [
        "coffee"
      ]
    },
    "name": {
      "type": "string",
      "default": "Espresso",
      "examples": [
        "Espresso"
      ]
    },
    "isAvailable": {
      "type": "boolean",
      "default": true,
      "examples": [
        true,
        false
      ]
    },
    "product-description": {
      "type": "string",
      "default": "A rich, dark, and full-bodied coffee with a bold flavor and intense aroma.",
      "examples": [
        "A rich, dark, and full-bodied coffee with a bold flavor and intense aroma."
      ]
    },
    "additionalText": {
      "type": "string",
      "default": "Contains caffeine",
      "examples": [
        "Contains caffeine"
      ]
    }
  },
  "required": [
    "id",
    "category",
    "name",
    "isAvailable",
    "product-description",
    "additionalText"
  ],
  "additionalProperties": false
}

pm.test("Response to match schema", function () {
    pm.response.to.have.jsonSchema(schema);
});

Can you share your collection?

The tip for these failing requests is to look at the pre-defined test in the submit\verify your work request.

If necessary, clone the request so you don’t edit the original request, and then add console logs for the variables in the test so you can see what is going on. It can be something as simple as a typo.

What the submit requests usually do is to send a request to the Postman collection endpoint which returns an JSON representation of your collection. It will then have a series of tests checking that response for certain elements covered in the training.

I’m not 100% sure which assignment this is, so sharing the collection is the easiest way to get an accurate response on why its failing. I need to see the failing test and what its actually doing first.

You would then usually check that test against the response JSON to see if those elements exist.

If you struggle, you can add console logs to the cloned submit request to get a better understanding of what the test is doing.

A lot of the time is just a spelling mistake, which then causes a variable to return undefined, breaking the test.

Your failing test is showing “expected undefined to deeply equal 1001”.

So you are getting an undefined variable that needs troubleshooting.

This is the course:

https://www.postman.com/valentins-team/test-automation-valentino-s-artisan-coffee-house-api/overview

The following in the post response scripts is adding the tests from the “Get Single Product” to the “Verify your work” tests.

request = folder.item.find(r => { return r.name === "Get single product"});
userTests = request.event.find(event => event.listen === 'test');
eval(userTests.script.exec.join('\n').replace('\"', '"'));

It’s failing on the “Product is bagel” test because the test is running against the collection JSON response, not the products endpoint.

pm.expect(response.id).to.eql........

The response.id will be undefined in the “Submit your request”.

I guess this is a case of reading the instructions for that assignment. Does it ask for this test to be created?

The schema test passes at there is a bit of code mocking the response that only appears to be available to the schema test.