cloud-gov / cg-ui

for the 2024 18F-supported cloud.gov product UI formerly known as the Stratos Dashboard
Other
3 stars 0 forks source link

Re-implement controller test where second wave of requests to CF / UAA APIs fail #258

Open jduss4 opened 3 months ago

jduss4 commented 3 months ago

This test was removed when the UAA API /Users endpoint was added, as nock was reluctant to allow the second /roles CF request to match. See previous discussion and code here: https://github.com/cloud-gov/cg-ui/pull/254/files#r1626583204

Acceptance Criteria

jduss4 commented 3 months ago

I created 3 scenarios, 2 of which cause a DIFFERENT test to fail. It would appear the nock discrepancy is somehow related to how the async / promise stuff is expressed, although I am unclear why it is happening in this case and NOT in other cases. If I comment out the test which it reports is failing, however, example 3 passes as expected.

When no tests are commented out:

🟢 Example 1 : 200 response and await

nock(process.env.UAA_API_URL).get(/Users/).reply(200, mockUaaUsers);

const result = await getOrgPage('orgGuid');
expect(result).toBeDefined();

🔴 Example 2: 200 response and wrapping function call

nock(process.env.UAA_API_URL).get(/Users/).reply(200, mockUaaUsers);

expect(getOrgPage('orgGuid')).resolves.toBeDefined();

Result for "getOrgPage > if the CF requests succeed > returns the expected controller result"

Error: something went wrong: Nock: No match for request

🔴 Example 3: 500 response and wrapping function call

nock(process.env.UAA_API_URL).get(/Users/).reply(500);

expect(async () => {
    await getOrgPage('orgGuid');
}).rejects.toThrow(new Error('something went wrong with the request'));

Result for "getOrgPage > if the CF requests succeed > returns the expected controller result"

Error: something went wrong: Nock: No match for request

jduss4 commented 1 month ago

I do not understand what the difficulty is here. But sure enough, even though UAA is no longer in the picture, and even though we have a successful test with the EXACT SAME SECOND REQUEST, something about making it respond as 500 instead of 200 throws nock off its game.