Skip to content

Commit

Permalink
Issue #SB-16090 merge: Merge pull request #234 from Ajoymaity/release…
Browse files Browse the repository at this point in the history
…-2.7.0

Issue #SB-16090 test: Unit test for profile import handler
  • Loading branch information
AmiableAnil authored Jan 8, 2020
2 parents bbc18ad + 1e458f4 commit 75faf10
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/profile/handler/import/transport-framework-n-channel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ describe('TransportFrameworkNChannel', () => {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn(() => of([{
key: 'sample-key',
value: 'sample-value',
_id: 'sample-id',
uid: 'uid',
gid: 'gid'
}]));
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of({});
});
mockDbService.insert = jest.fn(() => of(1));
// act
transportFrameworkNChannel.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});
Expand Down
48 changes: 48 additions & 0 deletions src/profile/handler/import/transport-group-profile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {TransportGroupProfile} from './transport-group-profile';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

describe('TransportGroupProfile', () => {
let transportGroupProfile: TransportGroupProfile;
const mockDbService: Partial<DbService> = {};

beforeAll(() => {
transportGroupProfile = new TransportGroupProfile(
mockDbService as DbService
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of TransportGroupProfile', () => {
expect(transportGroupProfile).toBeTruthy();
});

it('should saved group profile in local from Db', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of({});
});
mockDbService.insert = jest.fn(() => of(1));
// act
transportGroupProfile.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});
});
75 changes: 75 additions & 0 deletions src/profile/handler/import/transport-group.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { TransportGroup } from './transport-group';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

describe('TransportGroup', () => {
let transportGroup: TransportGroup;
const mockDbService: Partial<DbService> = {};

beforeAll(() => {
transportGroup = new TransportGroup(
mockDbService as DbService
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of TransportGroupProfile', () => {
expect(transportGroup).toBeTruthy();
});

it('should saved group in local from Db', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of({});
});
mockDbService.insert = jest.fn(() => of(1));

// act
transportGroup.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});


it('should saved group in local from Db for Failed', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of([{}]);
});

// act
transportGroup.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
done();
});
});
});
72 changes: 72 additions & 0 deletions src/profile/handler/import/transport-profiles.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {TransportProfiles} from './transport-profiles';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

describe('TransportProfiles', () => {
let transportProfiles: TransportProfiles;
const mockDbService: Partial<DbService> = {};

beforeAll(() => {
transportProfiles = new TransportProfiles(
mockDbService as DbService
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of TransportGroupProfile', () => {
expect(transportProfiles).toBeTruthy();
});

it('should saved profile and transport to db', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of({});
});
mockDbService.insert = jest.fn(() => of(1));
// act
transportProfiles.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});

it('should saved profile to db for import context failed', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of([{}]);
});
// act
transportProfiles.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
done();
});
});
});
48 changes: 48 additions & 0 deletions src/profile/handler/import/transport-user.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { TransportUser } from './transport-user';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

describe('TransportUser', () => {
let transportUser: TransportUser;
const mockDbService: Partial<DbService> = {};

beforeAll(() => {
transportUser = new TransportUser(
mockDbService as DbService
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of TransportGroupProfile', () => {
expect(transportUser).toBeTruthy();
});

it('should saved user profile in Db', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn((req) => {
if (req.useExternalDb) {
return of([{
uid: 'sample-uid',
gid: 'sample-gid'
}]);
}

return of({});
});
mockDbService.insert = jest.fn(() => of(1));
// act
transportUser.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { UpdateImportedProfileMetadata } from './update-imported-profile-metadata';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

describe('TransportUser', () => {
let updateImportedProfileMetadata: UpdateImportedProfileMetadata;
const mockDbService: Partial<DbService> = {};

beforeAll(() => {
updateImportedProfileMetadata = new UpdateImportedProfileMetadata(
mockDbService as DbService
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of TransportGroupProfile', () => {
expect(updateImportedProfileMetadata).toBeTruthy();
});

it('should update import profile metadate', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn(() => {
return of([{
imported_id: 'sample-imported_id',
device_id: 'sample-device_id',
count: 'count-1'
}]);
});
mockDbService.update = jest.fn(() => of(1));
// act
updateImportedProfileMetadata.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.update).toHaveBeenCalled();
done();
});
});

it('should should not updated profile metadata for else part', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn(() => of({}));
mockDbService.insert = jest.fn(() => of(1));
// act
updateImportedProfileMetadata.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
done();
});
});
});
Loading

0 comments on commit 75faf10

Please sign in to comment.