Skip to content

Commit 938f4f3

Browse files
guguclaude
andcommitted
fix: resolve unhandled errors in test suite
- Fix connect-db.component.spec.ts: wrap response in { connection: ... } to match expected updateConnection response structure - Fix connections.service.spec.ts: add missing mock methods - Add checkMasterPassword to fakeMasterPassword mock - Add dismissAlert to fakeNotifications mock - Convert updateConnection error test from async/await to subscribe pattern to properly handle Observable errors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f20d272 commit 938f4f3

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

frontend/src/app/components/connect-db/connect-db.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('ConnectDBComponent', () => {
210210
});
211211

212212
it('should update direct connection', () => {
213-
fakeConnectionsService.updateConnection.mockReturnValue(of(connectionCredsApp));
213+
fakeConnectionsService.updateConnection.mockReturnValue(of({ connection: connectionCredsApp }));
214214
vi.spyOn(component, 'db', 'get').mockReturnValue(connectionCredsApp);
215215
component.updateConnectionRequest();
216216

frontend/src/app/services/connections.service.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ describe('ConnectionsService', () => {
9696
showErrorSnackbar: vi.fn(),
9797
showSuccessSnackbar: vi.fn(),
9898
showAlert: vi.fn(),
99+
dismissAlert: vi.fn(),
99100
};
100101
fakeMasterPassword = {
101102
showMasterPasswordDialog: vi.fn(),
103+
checkMasterPassword: vi.fn(),
102104
};
103105

104106
TestBed.configureTestingModule({
@@ -471,20 +473,25 @@ describe('ConnectionsService', () => {
471473
req.flush(connectionCredsNetwork);
472474
});
473475

474-
it('should fall for updateConnection and show Error alert', async () => {
475-
const updatedConnection = service.updateConnection(connectionCredsApp, 'master_key_12345678').toPromise();
476+
it('should fall for updateConnection and show Error alert', () => {
477+
let errorCaught = false;
478+
479+
service.updateConnection(connectionCredsApp, 'master_key_12345678').subscribe({
480+
next: () => {
481+
// Should not be called
482+
},
483+
error: (error) => {
484+
errorCaught = true;
485+
expect(error.message).toEqual(fakeError.message);
486+
},
487+
});
476488

477489
const req = httpMock.expectOne(`/connection/9d5f6d0f-9516-4598-91c4-e4fe6330b4d4`);
478490
expect(req.request.method).toBe('PUT');
479491
expect(req.request.body).toEqual(connectionCredsRequested);
480492
req.flush(fakeError, { status: 400, statusText: '' });
481493

482-
try {
483-
await updatedConnection;
484-
} catch (error) {
485-
expect((error as Error).message).toEqual(fakeError.message);
486-
}
487-
494+
expect(errorCaught).toBe(true);
488495
expect(fakeNotifications.showAlert).toHaveBeenCalledWith(
489496
AlertType.Error,
490497
{ abstract: fakeError.message, details: fakeError.originalMessage },

0 commit comments

Comments
 (0)