Skip to content

Commit 0bdef84

Browse files
authored
fix(mixin): refactor test cases related to pr 108 (#109)
refactor test cases related to pr 108 gh-107
1 parent 2aad7e0 commit 0bdef84

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

src/__tests__/acceptance/audit.mixin.acceptance.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {expect, sinon} from '@loopback/testlab';
22
import {v4 as uuidv4} from 'uuid';
3-
import {Action, User} from '../..';
3+
import {Action} from '../..';
44
import {TestAuditDataSource} from './fixtures/datasources/audit.datasource';
55
import {TestDataSource} from './fixtures/datasources/test.datasource';
66
import {TestModel} from './fixtures/models/test.model';
@@ -10,24 +10,13 @@ import {
1010
testAuditOpts,
1111
TestRepository,
1212
} from './fixtures/repositories/test.repository';
13+
import {mockUser} from '../unit/fixtures/mockData';
1314

1415
export let consoleMessage: string;
1516
console.error = (message: string) => {
1617
consoleMessage = message;
1718
};
1819

19-
const mockUser: User = {
20-
id: 'testCurrentUserId',
21-
username: 'testCurrentUserName',
22-
authClientId: 123,
23-
permissions: ['1', '2', '3'],
24-
role: 'admin',
25-
firstName: 'test',
26-
lastName: 'lastname',
27-
tenantId: 'tenantId',
28-
userTenantId: 'userTenantId',
29-
};
30-
3120
describe('Audit Mixin', () => {
3221
const testDataSourceInstance = new TestDataSource();
3322
const getCurrentUser = sinon.stub().resolves(mockUser);

src/__tests__/unit/audit.mixin.unit.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
AuditLog,
77
AuditRepositoryMixin,
88
IAuditMixinOptions,
9-
User,
109
} from '../..';
1110
import {consoleMessage} from '../acceptance/audit.mixin.acceptance';
1211
import {
@@ -15,7 +14,12 @@ import {
1514
optionsReceivedByParentRepository,
1615
resetMethodCalls,
1716
} from './fixtures/mockClass';
18-
import {mockData, mockDataArray, resetMockData} from './fixtures/mockData';
17+
import {
18+
mockData,
19+
mockDataArray,
20+
mockUser,
21+
resetMockData,
22+
} from './fixtures/mockData';
1923
import {MockModel} from './fixtures/mockModel';
2024

2125
let auditData: AuditLog;
@@ -50,15 +54,6 @@ class MockAuditRepoError {
5054
const mockOpts: IAuditMixinOptions = {
5155
actionKey: 'Test_Logs',
5256
};
53-
const mockUser: User = {
54-
id: 'testCurrentUserId',
55-
username: 'testCurrentUserName',
56-
role: 'admin',
57-
firstName: 'test',
58-
lastName: 'lastname',
59-
tenantId: 'tenantId',
60-
userTenantId: 'userTenantId',
61-
};
6257

6358
describe('Audit Mixin', () => {
6459
class ReturnedMixedClass extends AuditRepositoryMixin<

src/__tests__/unit/fixtures/mockData.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {User} from '../../../types';
12
import {MockModel} from './mockModel';
23

34
export const mockData: MockModel = {
@@ -26,6 +27,16 @@ export const mockData: MockModel = {
2627
},
2728
};
2829

30+
export const mockUser: User = {
31+
id: 'testCurrentUserId',
32+
username: 'testCurrentUserName',
33+
role: 'admin',
34+
firstName: 'test',
35+
lastName: 'lastname',
36+
tenantId: 'tenantId',
37+
userTenantId: 'userTenantId',
38+
};
39+
2940
export const mockDataArray: MockModel[] = [
3041
{
3142
id: 'testId1',

0 commit comments

Comments
 (0)