test: streamline password reset logic in user security tests and update change password method to use MEET_ADMIN_SECRET

This commit is contained in:
juancarmore 2025-06-19 12:20:49 +02:00
parent 0154947fcf
commit 13e651cf8d
3 changed files with 13 additions and 12 deletions

View File

@ -9,8 +9,6 @@ import {
ParticipantRole
} from '../../src/typings/ce';
const RECORDINGS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`;
export const expectErrorResponse = (
response: any,
status = 422,
@ -445,11 +443,9 @@ export const expectValidGetRecordingUrlResponse = (response: any, recordingId: s
expect(response.status).toBe(200);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
const parsedUrl = new URL(recordingUrl);
expect(parsedUrl.pathname).toBe(
`/recording/${recordingId}`
);
expect(parsedUrl.pathname).toBe(`/recording/${recordingId}`);
expect(parsedUrl.searchParams.get('secret')).toBeDefined();
};

View File

@ -1,8 +1,9 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { Express } from 'express';
import request from 'supertest';
import INTERNAL_CONFIG from '../../../../src/config/internal-config.js';
import { loginUser, startTestServer } from '../../../helpers/request-helpers.js';
import { MEET_ADMIN_SECRET } from '../../../../src/environment.js';
import { changePassword, loginUser, startTestServer } from '../../../helpers/request-helpers.js';
const USERS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/users`;
@ -42,6 +43,11 @@ describe('User API Security Tests', () => {
adminCookie = await loginUser();
});
afterEach(async () => {
// Reset password
await changePassword(MEET_ADMIN_SECRET, adminCookie);
});
it('should succeed when user is authenticated as admin', async () => {
const response = await request(app)
.post(`${USERS_PATH}/change-password`)
@ -51,9 +57,7 @@ describe('User API Security Tests', () => {
});
it('should fail when user is not authenticated', async () => {
const response = await request(app)
.post(`${USERS_PATH}/change-password`)
.send(changePasswordRequest);
const response = await request(app).post(`${USERS_PATH}/change-password`).send(changePasswordRequest);
expect(response.status).toBe(401);
});
});

View File

@ -1,4 +1,5 @@
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { MEET_ADMIN_SECRET } from '../../../../src/environment.js';
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
import { changePassword, loginUser, startTestServer } from '../../../helpers/request-helpers.js';
@ -12,7 +13,7 @@ describe('Users API Tests', () => {
afterEach(async () => {
// Reset password
await changePassword('admin', adminCookie);
await changePassword(MEET_ADMIN_SECRET, adminCookie);
});
describe('Change Password Tests', () => {