Skip to content

Commit

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

Issue #SB-16090 test: Unit test for import profile handlr
  • Loading branch information
AmiableAnil authored Jan 8, 2020
2 parents 69feaba + 5cbb207 commit bbc18ad
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { GenerateProfileImportTelemetry } from './generate-profile-import-telemetry';
import { DbService, TelemetryService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';
import { TelemetryLogger } from '../../../telemetry/util/telemetry-logger';

jest.mock('../../../telemetry/util/telemetry-logger');

describe('GenerateProfileImportTelemetry', () => {
let generateProfileImportTelemetry: GenerateProfileImportTelemetry;
const mockDbService: Partial<DbService> = {};
const mockTelemetryService: Partial<TelemetryService> = {
share: jest.fn(() => of(undefined))
};
(TelemetryLogger as any)['log'] = mockTelemetryService;

beforeAll(() => {
generateProfileImportTelemetry = new GenerateProfileImportTelemetry(
mockDbService as DbService
);
});

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

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

it('should generate import profile telemetry', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn(() => of([{
imported_id: 'sample-imported_id',
device_id: 'sample-device_id',
count: 'no-of-count'
}]));
// act
generateProfileImportTelemetry.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockTelemetryService.share).toHaveBeenCalled();
done();
}).catch((e) => {
console.error(e);
fail(e);
});
});
});
44 changes: 44 additions & 0 deletions src/profile/handler/import/transport-assesments.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {TransportAssesments} from './transport-assesments';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

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

beforeAll(() => {
transportAssesments = new TransportAssesments(
mockDbService as DbService
);
});

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

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

it('should delete unwanted assessment and save lerner assessment', (done) => {
// arrange
const request: ImportTelemetryContext = {
sourceDBFilePath: 'src/db/path',
metadata: { 'index': 1 }
};
mockDbService.read = jest.fn(() => of([{uid: 'sample-uid'}]));
mockDbService.execute = jest.fn(() => of({}));
mockDbService.insert = jest.fn(() => of(2));
mockDbService.update = jest.fn(() => of(2));
// act
transportAssesments.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(mockDbService.execute).toHaveBeenCalled();
expect(mockDbService.insert).toHaveBeenCalled();
expect(mockDbService.update).toHaveBeenCalled();

done();
});
});
});
43 changes: 43 additions & 0 deletions src/profile/handler/import/transport-framework-n-channel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { TransportFrameworkNChannel } from './transport-framework-n-channel';
import { DbService, ImportTelemetryContext } from '../../..';
import { of } from 'rxjs';

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

beforeAll(() => {
transportFrameworkNChannel = new TransportFrameworkNChannel(
mockDbService as DbService
);
});

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

it('should be create a instace of transportFrameworkNChannel', () => {
expect(transportFrameworkNChannel).toBeTruthy();
});

it('should save NoSqlEntry To Db', (done) => {
// arrange
const request: ImportTelemetryContext = {
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'
}]));
// act
transportFrameworkNChannel.execute(request).then(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
done();
});
});
});

0 comments on commit bbc18ad

Please sign in to comment.