Skip to content

Commit

Permalink
fix(demo): demo data is only created after login (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Jan 11, 2023
1 parent 30dc8d9 commit e83d0ab
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion e2e/integration/RecordingAttendanceOfChild.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Scenario: Recording attendance of a child - E2E test", function () {
cy.get('[placeholder="Search"]')
.focus()
.type(this.childName)
.wait(500)
.wait(1500)
.type("{downArrow}")
.type("{enter}");
cy.get("#mat-tab-label-0-2").click();
Expand Down
23 changes: 7 additions & 16 deletions src/app/core/demo-data/demo-data-initializer.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ describe("DemoDataInitializerService", () => {
);
});

it("it should login the default user after publishing the demo data", fakeAsync(() => {
it("it should publish the demo data after logging in the default user", fakeAsync(() => {
service.run();

expect(mockDemoDataService.publishDemoData).toHaveBeenCalled();
expect(mockSessionService.login).not.toHaveBeenCalled();

tick();

expect(mockSessionService.login).toHaveBeenCalled();
expect(mockSessionService.login).toHaveBeenCalledWith(
DemoUserGeneratorService.DEFAULT_USERNAME,
DemoUserGeneratorService.DEFAULT_PASSWORD
);
expect(mockDemoDataService.publishDemoData).not.toHaveBeenCalled();

tick();

expect(mockDemoDataService.publishDemoData).toHaveBeenCalled();
}));

it("should show a dialog while generating demo data", fakeAsync(() => {
Expand All @@ -112,16 +113,6 @@ describe("DemoDataInitializerService", () => {
expect(closeSpy).toHaveBeenCalled();
}));

it("should initialize the database before publishing", () => {
const database = TestBed.inject(Database) as PouchDatabase;
expect(database.getPouchDB()).toBeUndefined();

service.run();

expect(database.getPouchDB()).toBeDefined();
expect(database.getPouchDB().name).toBe(demoUserDBName);
});

it("should sync with existing demo data when another user logs in", fakeAsync(() => {
service.run();
const database = TestBed.inject(Database) as PouchDatabase;
Expand Down
19 changes: 5 additions & 14 deletions src/app/core/demo-data/demo-data-initializer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class DemoDataInitializerService {
}
this.registerDemoUsers();

this.initializeDefaultDatabase();
await this.demoDataService.publishDemoData();

dialogRef.close();

await this.localSession.login(
DemoUserGeneratorService.DEFAULT_USERNAME,
DemoUserGeneratorService.DEFAULT_PASSWORD
);

await this.demoDataService.publishDemoData();

dialogRef.close();

this.syncDatabaseOnUserChange();
}

Expand Down Expand Up @@ -122,13 +122,4 @@ export class DemoDataInitializerService {
this.liveSyncHandle = undefined;
}
}

private initializeDefaultDatabase() {
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
if (environment.session_type === SessionType.mock) {
this.pouchDatabase.initInMemoryDB(dbName);
} else {
this.pouchDatabase.initIndexedDB(dbName);
}
}
}
4 changes: 2 additions & 2 deletions src/app/core/permissions/ability/ability.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class AbilityService {
const userRules = this.getRulesForUser(rules);
if (userRules.length === 0 || userRules.length === rules.default?.length) {
// No rules or only default rules defined
const { name, roles } = this.sessionService.getCurrentUser();
const user = this.sessionService.getCurrentUser();
this.logger.warn(
`no rules found for user "${name}" with roles "${roles}"`
`no rules found for user "${user?.name}" with roles "${user?.roles}"`
);
}
this.updateAbilityWithRules(userRules);
Expand Down

0 comments on commit e83d0ab

Please sign in to comment.