Add user logout routes to test files - #1691
Conversation
|
I drafted this PR for now since I am not currently finished implementing all the logouts, but will undraft it once I am finished. I just had a few clarifying questions about some of the tests. |
| mocha.before(async () => { | ||
| // login | ||
| let res = await chai.request(app).post('/api/loginLogout/login') | ||
| .send({ username: testUser.username, password: testUser.password }); |
There was a problem hiding this comment.
If this is supposed to test both ADMIN and CSV roles, then it looks like it doesn't access the CSV role. The test looks like it simply runs ADMIN both times instead of depending on the role being looped. If this behavior is unintended, then I can make the appropriate changes.
There was a problem hiding this comment.
What I see seems very similar to the next test for the other roles:
mocha.describe('Admin role & CSV role:', () => {
for (const role in User.role) {
if (User.role[role] !== User.role.OBVIUS && User.role[role] !== User.role.EXPORT) {I see what you mean and you seem correct. I think it should login with the desired role and use that token. Thanks for offering to make that change.
Unlike the next test which should test everyone else, this one should only test these roles. Thus, I think it would be much better to check if the role is admin or csv rather than not the others. Then it will still work if more roles are added. If you agree, could you also do that?
There was a problem hiding this comment.
I adjusted the test to login with the same role, but I noticed that it would only pass if I changed the before hook to a beforeEach hook in src/server/test/web/meters.js on line 162. Otherwise, I kept getting the following errors for both admin and csv:
21 passing (35s)
2 failing
1) meters API
Admin role & CSV role:
should return all meters for ADMIN:
AssertionError: expected { id: 1, name: null, url: null, …(31) } to have property 'name' of 'Meter 1', but got null
at expectMetersToBeEquivalent (src/server/test/web/meters.js:54:26)
at Context.<anonymous> (src/server/test/web/meters.js:213:6)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2) meters API
Admin role & CSV role:
should return all meters for CSV:
AssertionError: expected { id: 1, name: null, url: null, …(31) } to have property 'name' of 'Meter 1', but got null
at expectMetersToBeEquivalent (src/server/test/web/meters.js:54:26)
at Context.<anonymous> (src/server/test/web/meters.js:213:6)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I tested and found that the same error message is given for export and obvius roles for the same test, regardless of whether before or beforeEach is used (This might be the expected outcome, but shouldn't be for admin or csv). I also found that there's no difference between using an after or afterEach hook on line 176, but I kept it as afterEach to be consistent. I'm unsure of why I would strictly need a beforeEach for this test, but I plan on leaving it like this unless you have any input.
|
|
Description
This PR cleans up tests suites by adding in a logout route to test users who login. When a test logs in, it should also clean up by logging out, so the authentication lifecycle follows a consistent pattern (login → perform the test → logout). This PR addresses the issue in the following files:
Fixes #1683
Type of change
Checklist
Limitations
No limitations.