Day 8: Run a collection - 30 day challenge

Getting an error on the Day 08: Run a collection challenge. The following is the fail of the test in submitting the test results.

FAIL - Tests added correctly | TypeError: Cannot read properties of undefined (reading โ€˜findโ€™)

Hey @material-meteorolog3 :wave:

Welcome to the Postman Community! :postman:

Do you have tests within each of the individual requests, in the Run a collection folder?

Thank you for the reply and for welcoming me to the community. I do not have tests within each individual request.

The only tests are in the Submit your solution folder. The following are the tests that are running:

/ counter for passed tests
let pass = 0
let totalToPass = 5

let collection = pm.response.json().collection

pm.test("If you have any failures, review the failed test results or ask for support in the community forum. Remember to save your changes if you update the collection. When all of your tests pass, you are done with today's challenge.", () => {
    pm.expect(true);
    pass += 1
});

pm.test("Status code is 200", () => {
    pm.response.to.have.status(200);
    pass += 1
});

pm.test("Correct collection returned", () => {
    pm.expect(collection.info.name).equals("Day 08: Run a collection")
    pass += 1
})

pm.test("Requests added correctly", () => {
    pm.expect(collection.item[0].item.length, 'check number of requests').equals(3)

    let userRequest = collection.item[0].item.find(req => { return req.name === "get random user"})
    pm.expect(userRequest.name, 'check name').equals("get random user")
    pm.expect(userRequest.request.method, 'check method').equals("GET")

    let femaleRequest = collection.item[0].item.find(req => { return req.name === "get female user"})
    pm.expect(femaleRequest.name, 'check name').equals("get female user")
    pm.expect(femaleRequest.request.method, 'check method').equals("GET")
    pm.expect(femaleRequest.request.url.query.length, 'check params').equals(1)
    pm.expect(femaleRequest.request.url.query[0].key, 'check param key').equals("gender")
    pm.expect(femaleRequest.request.url.query[0].value, 'check param value').equals("female")

    let frenchRequest = collection.item[0].item.find(req => { return req.name === "get french user"})
    pm.expect(frenchRequest.name, 'check name').equals("get french user")
    pm.expect(frenchRequest.request.method, 'check method').equals("GET")
    pm.expect(frenchRequest.request.url.query.length, 'check params').equals(2)
    pm.expect(frenchRequest.request.url.query[0].key, 'check gender param key').equals("gender")
    pm.expect(frenchRequest.request.url.query[0].value, 'check gender param value').equals("female")
    pm.expect(frenchRequest.request.url.query[1].key, 'check nationality param key').equals("nat")
    pm.expect(frenchRequest.request.url.query[1].value, 'check nationality param value').to.be.oneOf(["FR", "fr"])
    
    pass += 1
})

pm.test("Tests added correctly", () => {
    let userRequest = collection.item[0].item.find(req => { return req.name === "get random user"})
    let userTest = userRequest.event.find(event => { return event.listen === "test" })
    pm.expect(userTest.listen).equals("test")

    let femaleRequest = collection.item[0].item.find(req => { return req.name === "get female user"})
    let femaleTest = femaleRequest.event.find(event => { return event.listen === "test" })
    pm.expect(femaleTest.listen).equals("test")

    let frenchRequest = collection.item[0].item.find(req => { return req.name === "get french user"})
    let frenchTest = frenchRequest.event.find(event => { return event.listen === "test"})
    pm.expect(frenchTest.listen).equals("test")

    pass += 1
})

// visualization for test results
let template
if (pass == totalToPass) {
    template = `๐Ÿช passing!
        <br />
        <img src="https://media3.giphy.com/media/Vi6fwn76gPynTeoL6W/giphy.gif?cid=ecf05e47o0lq8mn5h13ju9aawk2ecwz16wwtcbryru7aa2g9&rid=giphy.gif&ct=g" />
    `
} else {
    template = `๐Ÿ™… please try again
        <br />
        <img src="https://media0.giphy.com/media/YmVNzDnboB0RQEpmLr/giphy.gif?cid=ecf05e47v5aqnsbm3b0a0bpxd4rs2qcaec1byw6v9fm7swzv&rid=giphy.gif&ct=g" />
    `
}
pm.visualizer.set(template)

If you read the documentation for the task, it mentions that each of the requests that you add, should have tests.

Thank you. Please excuse me for completely overlooking those instructions. Including individual tests in each request was the issue.

1 Like

Itโ€™s all good - If it wasnโ€™t clear we can make adjustments to the documentation to make that more explicit, if needed.

Here to help out with everything and at every step of the journey.

Good luck with the remaining days. :trophy:

No need to make any changes, I think it was clear. It was an oversight on my part. Thanks again!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.