-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #SB-16090 merge: Merge pull request #233 from Ajoymaity/release…
…-2.7.0 Issue #SB-16090 test: Unit test for import profile handlr
- Loading branch information
Showing
3 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/profile/handler/import/generate-profile-import-telemetry.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/profile/handler/import/transport-framework-n-channel.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |