Skip to content

Commit

Permalink
changed test db
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-fabian committed May 24, 2024
1 parent 10618d0 commit 007292f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cspell.words.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
webauthn
whitesmoke
simplewebauthn
RPID
RPID
cicd
22 changes: 21 additions & 1 deletion src/__tests__/fixtures/db.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unusedImports/no-unused-vars */
import { inject, lifeCycleObserver, LifeCycleObserver } from '@loopback/core';
import { juggler } from '@loopback/repository';

Expand Down Expand Up @@ -38,4 +39,23 @@ export class DbDataSource extends juggler.DataSource implements LifeCycleObserve
/**
* Database used for testing. This is a mysql connection to test transactions.
*/
export const testDb: DbDataSource = new DbDataSource();
const mysqlTestDb: DbDataSource = new DbDataSource();

/**
* Database used for testing. This is a in memory connection to use in cicd.
*/
const inMemoryTestDb: juggler.DataSource = new juggler.DataSource({
name: 'db',
connector: 'memory'
});
inMemoryTestDb.beginTransaction = async () => {
return {
commit: () => {},
rollback: () => {}
};
};

/**
* Database used for testing.
*/
export const testDb: juggler.DataSource = inMemoryTestDb;
4 changes: 2 additions & 2 deletions src/__tests__/unit/refresh-token.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('RefreshTokenService', () => {

// we need to wait so that the time part in the new access token is different.
// (at least the seconds need to differ)
await sleep(1000);
await sleep(1500);

const newTokenObject: TokenObject = await testRefreshTokenService.refreshToken(oldRefreshTokenValue);

Expand All @@ -57,7 +57,7 @@ describe('RefreshTokenService', () => {
}
await testRefreshTokenRepository.updateById(refreshToken.id, { expirationDate: new Date() });

await sleep(1000);
await sleep(1500);

const newTokenObjectTwo: TokenObject = await testRefreshTokenService.refreshToken(oldRefreshTokenValue);

Expand Down
17 changes: 9 additions & 8 deletions src/__tests__/unit/two-factor.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/no-null */
import { expect } from '@loopback/testlab';

import { OtpAuthUtilities } from '../../encapsulation/otp-auth.utilities';
Expand All @@ -16,16 +17,16 @@ describe('TwoFactorService', () => {
await clearDatabase();
user = await createExampleUser();
const credentials: Credentials = await testUserRepository.credentials(user.id).get();
expect(credentials.twoFactorAuthUrl).to.be.null();
expect(credentials.twoFactorSecret).to.be.null();
expect(user.twoFactorEnabled).to.be.undefined();
expect(credentials.twoFactorAuthUrl).to.be.oneOf(null, undefined);
expect(credentials.twoFactorSecret).to.be.oneOf(null, undefined);
expect(user.twoFactorEnabled).to.be.oneOf(null, undefined);
});
it('turnOn2FA', async () => {
await twoFactorService.turnOn2FA(user.id);
const credentials: Credentials = await testUserRepository.credentials(user.id).get();
expect(credentials.twoFactorAuthUrl).to.not.be.null();
expect(credentials.twoFactorSecret).to.not.be.null();
expect((await testUserRepository.findById(user.id)).twoFactorEnabled).to.be.null();
expect(credentials.twoFactorAuthUrl).to.not.be.oneOf(null, undefined);
expect(credentials.twoFactorSecret).to.not.be.oneOf(null, undefined);
expect((await testUserRepository.findById(user.id)).twoFactorEnabled).to.be.oneOf(null, undefined);
});

it('confirmTurnOn2FA', async () => {
Expand All @@ -39,8 +40,8 @@ describe('TwoFactorService', () => {
await twoFactorService.turnOff2FA(user.id);

let credentials: Credentials = await testUserRepository.credentials(user.id).get();
expect(credentials.twoFactorAuthUrl).to.be.null();
expect(credentials.twoFactorSecret).to.be.null();
expect(credentials.twoFactorAuthUrl).to.be.oneOf(null, undefined);
expect(credentials.twoFactorSecret).to.be.oneOf(null, undefined);

user = await testUserRepository.findById(user.id);
expect(user.twoFactorEnabled).to.be.false();
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit 007292f

Please sign in to comment.