Skip to content

Commit 33aa897

Browse files
committed
fix tests
1 parent 44a31a5 commit 33aa897

3 files changed

Lines changed: 23 additions & 47 deletions

File tree

frontend/buildspec.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

frontend/src/app/components/secrets/audit-log-dialog/audit-log-dialog.component.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ describe('AuditLogDialogComponent', () => {
3535
success: true,
3636
};
3737

38-
const mockAuditLogResponse: AuditLogResponse = {
38+
const createMockAuditLogResponse = (): AuditLogResponse => ({
3939
data: [mockAuditLogEntry],
4040
pagination: { total: 1, currentPage: 1, perPage: 20, lastPage: 1 },
41-
};
41+
});
4242

43-
const mockMultipleLogsResponse: AuditLogResponse = {
43+
const createMockMultipleLogsResponse = (): AuditLogResponse => ({
4444
data: [
4545
mockAuditLogEntry,
4646
{
@@ -74,11 +74,11 @@ describe('AuditLogDialogComponent', () => {
7474
},
7575
],
7676
pagination: { total: 5, currentPage: 1, perPage: 20, lastPage: 1 },
77-
};
77+
});
7878

7979
beforeEach(async () => {
8080
mockSecretsService = jasmine.createSpyObj('SecretsService', ['getAuditLog']);
81-
mockSecretsService.getAuditLog.and.returnValue(of(mockAuditLogResponse));
81+
mockSecretsService.getAuditLog.and.callFake(() => of(createMockAuditLogResponse()));
8282

8383
mockDialogRef = jasmine.createSpyObj('MatDialogRef', ['close']);
8484

@@ -204,23 +204,23 @@ describe('AuditLogDialogComponent', () => {
204204
describe('loadAuditLog', () => {
205205
it('should set loading to true while fetching', () => {
206206
component.loading = false;
207-
mockSecretsService.getAuditLog.and.returnValue(of(mockAuditLogResponse));
207+
mockSecretsService.getAuditLog.and.callFake(() => of(createMockAuditLogResponse()));
208208

209209
component.loadAuditLog();
210210

211211
expect(component.loading).toBeFalse();
212212
});
213213

214214
it('should update logs on successful fetch', () => {
215-
mockSecretsService.getAuditLog.and.returnValue(of(mockMultipleLogsResponse));
215+
mockSecretsService.getAuditLog.and.callFake(() => of(createMockMultipleLogsResponse()));
216216

217217
component.loadAuditLog();
218218

219219
expect(component.logs.length).toBe(5);
220220
});
221221

222222
it('should update pagination on successful fetch', () => {
223-
mockSecretsService.getAuditLog.and.returnValue(of(mockMultipleLogsResponse));
223+
mockSecretsService.getAuditLog.and.callFake(() => of(createMockMultipleLogsResponse()));
224224

225225
component.loadAuditLog();
226226

@@ -246,6 +246,11 @@ describe('AuditLogDialogComponent', () => {
246246
length: 100
247247
};
248248

249+
// Update mock to return pagination matching the page change
250+
mockSecretsService.getAuditLog.and.callFake(() => of({
251+
data: [mockAuditLogEntry],
252+
pagination: { total: 100, currentPage: 3, perPage: 50, lastPage: 2 }
253+
}));
249254
mockSecretsService.getAuditLog.calls.reset();
250255
component.onPageChange(pageEvent);
251256

@@ -270,7 +275,7 @@ describe('AuditLogDialogComponent', () => {
270275

271276
describe('with multiple audit log entries', () => {
272277
beforeEach(() => {
273-
mockSecretsService.getAuditLog.and.returnValue(of(mockMultipleLogsResponse));
278+
mockSecretsService.getAuditLog.and.callFake(() => of(createMockMultipleLogsResponse()));
274279
component.loadAuditLog();
275280
});
276281

frontend/src/app/components/secrets/secrets.component.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ describe('SecretsComponent', () => {
3434
masterEncryption: false,
3535
};
3636

37-
const mockSecretsResponse = {
37+
const createMockSecretsResponse = () => ({
3838
data: [mockSecret],
3939
pagination: { total: 1, currentPage: 1, perPage: 20, lastPage: 1 }
40-
};
40+
});
4141

4242
beforeEach(async () => {
4343
secretsUpdatedSubject = new BehaviorSubject<string>('');
4444

4545
mockSecretsService = jasmine.createSpyObj('SecretsService', ['fetchSecrets'], {
4646
cast: secretsUpdatedSubject.asObservable()
4747
});
48-
mockSecretsService.fetchSecrets.and.returnValue(of(mockSecretsResponse));
48+
mockSecretsService.fetchSecrets.and.callFake(() => of(createMockSecretsResponse()));
4949

5050
mockCompanyService = jasmine.createSpyObj('CompanyService', ['getCurrentTabTitle']);
5151
mockCompanyService.getCurrentTabTitle.and.returnValue(of('Test Company'));
@@ -215,6 +215,11 @@ describe('SecretsComponent', () => {
215215
length: 100
216216
};
217217

218+
// Update mock to return pagination matching the page change
219+
mockSecretsService.fetchSecrets.and.callFake(() => of({
220+
data: [mockSecret],
221+
pagination: { total: 100, currentPage: 2, perPage: 10, lastPage: 10 }
222+
}));
218223
mockSecretsService.fetchSecrets.calls.reset();
219224
component.onPageChange(pageEvent);
220225

@@ -269,7 +274,7 @@ describe('SecretsComponent', () => {
269274
describe('loadSecrets', () => {
270275
it('should set loading to true while fetching', () => {
271276
component.loading = false;
272-
mockSecretsService.fetchSecrets.and.returnValue(of(mockSecretsResponse));
277+
mockSecretsService.fetchSecrets.and.callFake(() => of(createMockSecretsResponse()));
273278

274279
component.loadSecrets();
275280

0 commit comments

Comments
 (0)