Skip to content

Commit

Permalink
fix(mixin): refactor test cases related to pr 108 (#109)
Browse files Browse the repository at this point in the history
refactor test cases related to pr 108

gh-107
  • Loading branch information
Tyagi-Sunny committed Apr 3, 2024
1 parent 2aad7e0 commit 0bdef84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
15 changes: 2 additions & 13 deletions src/__tests__/acceptance/audit.mixin.acceptance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, sinon} from '@loopback/testlab';
import {v4 as uuidv4} from 'uuid';
import {Action, User} from '../..';
import {Action} from '../..';
import {TestAuditDataSource} from './fixtures/datasources/audit.datasource';
import {TestDataSource} from './fixtures/datasources/test.datasource';
import {TestModel} from './fixtures/models/test.model';
Expand All @@ -10,24 +10,13 @@ import {
testAuditOpts,
TestRepository,
} from './fixtures/repositories/test.repository';
import {mockUser} from '../unit/fixtures/mockData';

export let consoleMessage: string;
console.error = (message: string) => {
consoleMessage = message;
};

const mockUser: User = {
id: 'testCurrentUserId',
username: 'testCurrentUserName',
authClientId: 123,
permissions: ['1', '2', '3'],
role: 'admin',
firstName: 'test',
lastName: 'lastname',
tenantId: 'tenantId',
userTenantId: 'userTenantId',
};

describe('Audit Mixin', () => {
const testDataSourceInstance = new TestDataSource();
const getCurrentUser = sinon.stub().resolves(mockUser);
Expand Down
17 changes: 6 additions & 11 deletions src/__tests__/unit/audit.mixin.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AuditLog,
AuditRepositoryMixin,
IAuditMixinOptions,
User,
} from '../..';
import {consoleMessage} from '../acceptance/audit.mixin.acceptance';
import {
Expand All @@ -15,7 +14,12 @@ import {
optionsReceivedByParentRepository,
resetMethodCalls,
} from './fixtures/mockClass';
import {mockData, mockDataArray, resetMockData} from './fixtures/mockData';
import {
mockData,
mockDataArray,
mockUser,
resetMockData,
} from './fixtures/mockData';
import {MockModel} from './fixtures/mockModel';

let auditData: AuditLog;
Expand Down Expand Up @@ -50,15 +54,6 @@ class MockAuditRepoError {
const mockOpts: IAuditMixinOptions = {
actionKey: 'Test_Logs',
};
const mockUser: User = {
id: 'testCurrentUserId',
username: 'testCurrentUserName',
role: 'admin',
firstName: 'test',
lastName: 'lastname',
tenantId: 'tenantId',
userTenantId: 'userTenantId',
};

describe('Audit Mixin', () => {
class ReturnedMixedClass extends AuditRepositoryMixin<
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/unit/fixtures/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {User} from '../../../types';
import {MockModel} from './mockModel';

export const mockData: MockModel = {
Expand Down Expand Up @@ -26,6 +27,16 @@ export const mockData: MockModel = {
},
};

export const mockUser: User = {
id: 'testCurrentUserId',
username: 'testCurrentUserName',
role: 'admin',
firstName: 'test',
lastName: 'lastname',
tenantId: 'tenantId',
userTenantId: 'userTenantId',
};

export const mockDataArray: MockModel[] = [
{
id: 'testId1',
Expand Down

0 comments on commit 0bdef84

Please sign in to comment.