Skip to content

Commit 751b041

Browse files
Merge pull request #957 from rocket-admin/unit-tests
fix existing and initial tests
2 parents cf9f030 + 0063625 commit 751b041

File tree

42 files changed

+498
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+498
-332
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { UsersService } from 'src/app/services/users.service';
1212
import { of } from 'rxjs';
1313
import { LogAction, LogStatus } from 'src/app/models/logs';
1414
import { InfoDialogComponent } from './info-dialog/info-dialog.component';
15+
import { Angulartics2Module } from 'angulartics2';
1516

1617
describe('AuditComponent', () => {
1718
let component: AuditComponent;
@@ -77,7 +78,8 @@ describe('AuditComponent', () => {
7778
MatSnackBarModule,
7879
MatDialogModule,
7980
MatPaginatorModule,
80-
BrowserAnimationsModule
81+
BrowserAnimationsModule,
82+
Angulartics2Module.forRoot()
8183
],
8284
declarations: [ AuditComponent ]
8385
})

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,12 @@ describe('CompanyComponent', () => {
222222

223223
it('should open Add member dialog and pass company id and name', () => {
224224
const fakeAddMemberDialogOpen = spyOn(dialog, 'open');
225-
component.company.id = 'company-12345678';
226-
component.company.name = 'My company';
225+
component.company = mockCompany;
227226

228227
component.handleAddMemberDialogOpen();
229228
expect(fakeAddMemberDialogOpen).toHaveBeenCalledOnceWith(InviteMemberDialogComponent, {
230229
width: '25em',
231-
data: {id: 'company-12345678', name: 'My company'}
230+
data: mockCompany
232231
});
233232
});
234233

frontend/src/app/components/company/invite-member-dialog/invite-member-dialog.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('AddMemberDialogComponent', () => {
2121
Angulartics2Module.forRoot()
2222
],
2323
providers: [
24-
{ provide: MAT_DIALOG_DATA, useValue: { id: '' } },
24+
{ provide: MAT_DIALOG_DATA, useValue: { id: '', connections: [] } },
2525
{ provide: MatDialogRef, useValue: MatDialogRef }
2626
],
2727
})

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

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe('ConnectDBComponent', () => {
2424
let component: ConnectDBComponent;
2525
let fixture: ComponentFixture<ConnectDBComponent>;
2626
let dialog: MatDialog;
27-
let mockLocalStorage;
2827

2928
let fakeNotifications = jasmine.createSpyObj('NotificationsService', ['showErrorSnackbar', 'showSuccessSnackbar', 'showAlert', 'dismissAlert']);
3029
let fakeConnectionsService = jasmine.createSpyObj('ConnectionsService', [
@@ -87,26 +86,10 @@ describe('ConnectDBComponent', () => {
8786
component = fixture.componentInstance;
8887
dialog = TestBed.get(MatDialog);
8988

90-
let store = {};
91-
mockLocalStorage = {
92-
getItem: (key: string): string => {
93-
return key in store ? store[key] : null;
94-
},
95-
setItem: (key: string, value: string) => {
96-
store[key] = `${value}`;
97-
},
98-
removeItem: (key: string) => {
99-
delete store[key];
100-
},
101-
clear: () => {
102-
store = {};
103-
}
104-
};
105-
106-
// @ts-ignore
107-
global.window.fbq = jasmine.createSpy();
108-
// @ts-ignore
109-
global.window.Intercom = jasmine.createSpy();
89+
// @ts-ignore
90+
global.window.fbq = jasmine.createSpy();
91+
// @ts-ignore
92+
global.window.Intercom = jasmine.createSpy();
11093

11194
fakeConnectionsService.currentConnection.and.returnValue(connectionCredsApp);
11295
fakeConnectionsService.getCurrentConnectionTitle.and.returnValue(of('Test connection via SSH tunnel to mySQL'));
@@ -159,8 +142,8 @@ describe('ConnectDBComponent', () => {
159142
fakeNotifications.showSuccessSnackbar.calls.reset();
160143
});
161144

162-
it('should generate password', () => {
163-
component.generatePassword();
145+
it('should generate password if toggle is enabled', () => {
146+
component.generatePassword(true);
164147
expect(component.masterKey).toBeDefined();
165148
});
166149

@@ -175,29 +158,6 @@ describe('ConnectDBComponent', () => {
175158
});
176159
});
177160

178-
it('should write master key in localstorage if masterEncryption is turned on', () => {
179-
spyOn(localStorage, 'setItem').and.callFake(mockLocalStorage.setItem);
180-
181-
component.db.masterEncryption = true;
182-
component.masterKey = 'abcd-0987654321';
183-
component.connectionID = '12345678';
184-
185-
component.checkMasterPassword();
186-
187-
expect(localStorage.setItem).toHaveBeenCalledOnceWith('12345678__masterKey', 'abcd-0987654321');
188-
})
189-
190-
it('should remove master key in localstorage if masterEncryption is turned off', () => {
191-
spyOn(localStorage, 'removeItem').and.callFake(mockLocalStorage.removeItem);
192-
193-
component.db.masterEncryption = false;
194-
component.connectionID = '12345678';
195-
196-
component.checkMasterPassword();
197-
198-
expect(localStorage.removeItem).toHaveBeenCalledOnceWith('12345678__masterKey');
199-
})
200-
201161
it('should create direct connection', () => {
202162
fakeConnectionsService.createConnection.and.returnValue(of(connectionCredsApp));
203163
spyOnProperty(component, "db", "get").and.returnValue(connectionCredsApp);
@@ -268,12 +228,14 @@ describe('ConnectDBComponent', () => {
268228
it('should open dialog on test error', () => {
269229
const fakeDialogOpen = spyOn(dialog, 'open');
270230
spyOnProperty(component, "db", "get").and.returnValue(connectionCredsApp);
231+
component.masterKey = "master_password_12345678"
271232
component.handleConnectionError('Hostname is invalid');
272233

273234
expect(fakeDialogOpen).toHaveBeenCalledOnceWith(DbConnectionConfirmDialogComponent, {
274235
width: '25em',
275236
data: {
276237
dbCreds: connectionCredsApp,
238+
masterKey: 'master_password_12345678',
277239
errorMessage: 'Hostname is invalid'
278240
}
279241
});

frontend/src/app/components/connect-db/db-connection-confirm-dialog/db-connection-confirm-dialog.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, Inject, OnInit } from '@angular/core';
22
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
33
import { Router } from '@angular/router';
44
import { ConnectionsService } from 'src/app/services/connections.service';
5-
import { NotificationsService } from 'src/app/services/notifications.service';
65
import { DbConnectionDeleteDialogComponent } from '../db-connection-delete-dialog/db-connection-delete-dialog.component';
76
import { environment } from 'src/environments/environment';
87

@@ -21,7 +20,6 @@ export class DbConnectionConfirmDialogComponent implements OnInit {
2120
private _connections: ConnectionsService,
2221
public dialogRef: MatDialogRef<DbConnectionDeleteDialogComponent>,
2322
public router: Router,
24-
private _notifications: NotificationsService
2523
) { }
2624

2725
ngOnInit(): void {}

frontend/src/app/components/connect-db/db-credentials-forms/base-credentials-form/base-credentials-form.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('BaseCredentialsFormComponent', () => {
1111
imports: [BaseCredentialsFormComponent]
1212
})
1313
.compileComponents();
14-
14+
1515
fixture = TestBed.createComponent(BaseCredentialsFormComponent);
1616
component = fixture.componentInstance;
1717
fixture.detectChanges();

frontend/src/app/components/connect-db/db-credentials-forms/base-credentials-form/base-credentials-form.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@ export class BaseCredentialsFormComponent {
1313
@Input() readonly: boolean;
1414
@Input() submitting: boolean;
1515
@Input() masterKey: string;
16-
// @Input() isMasterKeyTurnedOn: boolean;
1716
@Input() accessLevel: string;
1817

1918
@Output() switchToAgent = new EventEmitter<void>();
2019
@Output() masterKeyChange = new EventEmitter<string>();
21-
// @Output() masterKeyToggle = new EventEmitter<boolean>();
2220

2321
public ngrokLink = "https://help.rocketadmin.com/en/articles/8556731-how-to-connect-a-local-database-via-ngrok";
2422

2523
handleMasterKeyChange(newMasterKey: string): void {
2624
this.masterKeyChange.emit(newMasterKey);
2725
}
28-
29-
// handleMasterKeyToggle(isTurnedOn: boolean): void {
30-
// this.masterKeyToggle.emit(isTurnedOn);
31-
// }
3226
}

frontend/src/app/components/connect-db/db-credentials-forms/dynamodb-credentials-form/dynamodb-credentials-form.component.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { DynamodbCredentialsFormComponent } from './dynamodb-credentials-form.component';
4+
import { FormsModule } from '@angular/forms';
45

56
describe('DynamodbCredentialsFormComponent', () => {
67
let component: DynamodbCredentialsFormComponent;
78
let fixture: ComponentFixture<DynamodbCredentialsFormComponent>;
89

910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
11-
imports: [DynamodbCredentialsFormComponent]
12+
declarations: [DynamodbCredentialsFormComponent],
13+
imports: [
14+
FormsModule
15+
]
1216
})
1317
.compileComponents();
14-
18+
1519
fixture = TestBed.createComponent(DynamodbCredentialsFormComponent);
1620
component = fixture.componentInstance;
21+
22+
component.connection = {
23+
id: "12345678"
24+
} as any;
25+
1726
fixture.detectChanges();
1827
});
1928

frontend/src/app/components/connect-db/db-credentials-forms/mongodb-credentials-form/mongodb-credentials-form.component.spec.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { MongodbCredentialsFormComponent } from './mongodb-credentials-form.component';
4+
import { FormsModule } from '@angular/forms';
5+
import { ConnectionType, DBtype } from 'src/app/models/connection';
6+
import { MatCheckboxModule } from '@angular/material/checkbox';
47

58
describe('MongodbCredentialsFormComponent', () => {
69
let component: MongodbCredentialsFormComponent;
710
let fixture: ComponentFixture<MongodbCredentialsFormComponent>;
811

912
beforeEach(async () => {
1013
await TestBed.configureTestingModule({
11-
imports: [MongodbCredentialsFormComponent]
14+
declarations: [MongodbCredentialsFormComponent],
15+
imports: [
16+
FormsModule,
17+
MatCheckboxModule
18+
]
1219
})
1320
.compileComponents();
14-
21+
1522
fixture = TestBed.createComponent(MongodbCredentialsFormComponent);
1623
component = fixture.componentInstance;
24+
25+
component.connection = {
26+
id: "12345678"
27+
} as any;
28+
29+
// component.connection = {
30+
// "title": "Test connection via SSH tunnel to mySQL",
31+
// "masterEncryption": false,
32+
// "type": DBtype.MySQL,
33+
// "host": "database-2.cvfuxe8nltiq.us-east-2.rds.amazonaws.com",
34+
// "port": "3306",
35+
// "username": "admin",
36+
// "database": "testDB",
37+
// "schema": null,
38+
// "sid": null,
39+
// "id": "9d5f6d0f-9516-4598-91c4-e4fe6330b4d4",
40+
// "ssh": true,
41+
// "sshHost": "3.134.99.192",
42+
// "sshPort": '22',
43+
// "sshUsername": "ubuntu",
44+
// "ssl": false,
45+
// "cert": null,
46+
// "connectionType": ConnectionType.Direct,
47+
// "azure_encryption": false,
48+
// "signing_key": ''
49+
// };
1750
fixture.detectChanges();
1851
});
1952

frontend/src/app/components/connect-db/db-credentials-forms/mssql-credentials-form/mssql-credentials-form.component.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { MssqlCredentialsFormComponent } from './mssql-credentials-form.component';
4+
import { FormsModule } from '@angular/forms';
5+
import { MatCheckboxModule } from '@angular/material/checkbox';
46

57
describe('MssqlCredentialsFormComponent', () => {
68
let component: MssqlCredentialsFormComponent;
79
let fixture: ComponentFixture<MssqlCredentialsFormComponent>;
810

911
beforeEach(async () => {
1012
await TestBed.configureTestingModule({
11-
imports: [MssqlCredentialsFormComponent]
13+
declarations: [MssqlCredentialsFormComponent],
14+
imports: [
15+
FormsModule,
16+
MatCheckboxModule
17+
]
1218
})
1319
.compileComponents();
14-
20+
1521
fixture = TestBed.createComponent(MssqlCredentialsFormComponent);
1622
component = fixture.componentInstance;
23+
24+
component.connection = {
25+
id: "12345678"
26+
} as any;
27+
1728
fixture.detectChanges();
1829
});
1930

0 commit comments

Comments
 (0)