Day 27 Authorisation test failing

When I submit my answer the “Authorisation added correctly” test is failing with “AssertionError: expected ‘header’ to equal ‘{{token}}’” and I can’t work out why.

Here is what I have for the authorisation of the folder and all the requests in the folder inherit from the parent. Please can anyone help?

When I look at the auth details in the response of the submit request I see.

                            "type": "apikey",
                            "apikey": [
                                {
                                    "key": "in",
                                    "value": "header",
                                    "type": "string"
                                },
                                {
                                    "key": "value",
                                    "value": "{{token}}",
                                    "type": "string"
                                },
                                {
                                    "key": "key",
                                    "value": "x-api-key",
                                    "type": "string"
                                }

And if I change the index from 0 to 1 in the test it passes pm.expect(newFlowFolder.auth.apikey[0].value).equals("{{token}}") - so have I done something wrong or has the auth information been formatted differently in the response?

I think you just need to “get” the token first as what you have here is literally putting “{{token}}” as a string…

Try something like this (change depending on where your token variable is stored);

pm.collectionVariables.get("token")
pm.globals.get("token");
pm.environment.get("token");

So the full check would be something like this…

pm.test("Check token", () => {
pm.expect(newFlowFolder.auth.apikey[0].value).equals(pm.collectionVariables.get("token"));
});

For the second part,
Arrays start at 0, so if you set ‘expect’ to equal “{{token}}” for [0] then it would fail as [0] doesn’t have this set… But [1] does have {{token}} set… I’ve added comments here so you can see the structure;

"type":"apikey",
"apikey":[ //<--- array starts here

//This is 0
	{
		"key":"in",
		"value":"header",
		"type":"string"
	},
//This is 1
	{
		"key":"value",
		"value":"{{token}}",
		"type":"string"
	},
//This is 2
	{
		"key":"key",
		"value":"x-api-key",
		"type":"string"
	}
1 Like

Thank you for your reply.

The {{token}} is a collection variable and when I hover over it in the authorization for the folder it is displayed ok so it should be getting the value of the variable OK, I believe.

The test that fails uses the array above that you have commented. Index 0 fails however if I change the test to index 1 it passes - that is why I am asking if something has changed in the array since the test was written as it looks like the test should be on index 1 item.

It is possible that the apikey array was changed to include the items that now live in index [0] (pushing your token check to index [1])… But you’d have to check with the API developer(s) to confirm… Or go through test run logs / check history etc.

In postman on the left you might be able to use the “history” tab to go back and look at what the response used to be…

1 Like

Thank you. I’ll investigate.