-
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 #234 from Ajoymaity/release…
…-2.7.0 Issue #SB-16090 test: Unit test for profile import handler
- Loading branch information
Showing
7 changed files
with
410 additions
and
7 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
src/profile/handler/import/transport-group-profile.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,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(); | ||
}); | ||
}); | ||
}); |
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,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(); | ||
}); | ||
}); | ||
}); |
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,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(); | ||
}); | ||
}); | ||
}); |
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,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(); | ||
}); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
src/profile/handler/import/update-imported-profile-metadata.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,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(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.