-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user-segment.service specs #195
Closed
Closed
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3d2f7f1
Merge pull request #168 from samagra-comms/develop
chinmoy12c 7b4e1d0
Merge pull request #170 from samagra-comms/develop
chinmoy12c 80d4631
Merge pull request #181 from samagra-comms/develop
chinmoy12c 05e778d
added healthController specs
1010varun 211a821
Merge branch 'samagra-comms:develop' into develop
1010varun 9aba65d
Merge branch 'samagra-comms:develop' into develop
1010varun 040fb58
added user-segment Controller specs
1010varun 71889cb
made review chanages
1010varun d71f6f9
Merge pull request #193 from samagra-comms/develop
chinmoy12c 81e6b47
Merge branch 'samagra-comms:develop' into develop
1010varun e394f52
transformer.controller specs
1010varun 46d9baf
user-segment.service specs
1010varun 684ad93
Fixed error message on bad date format in bot update. (#197)
chinmoy12c 70d5390
* Refactored search/internal endpoint. (#177)
chinmoy12c ae5cd0e
Adds order by parameter in search API.
geeky-abhishek 6e62c5c
Invalidates cache on transaction layer on bot update. (#204)
chinmoy12c 3b59762
Adds monitoring module for fetching logs data. (#203)
chinmoy12c 4ec244d
Hotfix incorrect substring values and unhandled directory close. (#205)
chinmoy12c cbf5e51
Merge branch 'samagra-comms:master' into 1010varun-patch1
1010varun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
148 changes: 138 additions & 10 deletions
148
src/modules/transformer/transformer.controller.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 |
---|---|---|
@@ -1,20 +1,148 @@ | ||
import { TransformerService } from './transformer.service'; | ||
import { TransformerController } from './transformer.controller'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ConversationLogicController } from '../conversation-logic/conversation-logic.controller'; | ||
import { ConversationLogicService } from '../conversation-logic/conversation-logic.service'; | ||
import { AddOwnerInfoInterceptor } from '../../interceptors/addOwnerInfo.interceptor'; | ||
import { AddAdminHeaderInterceptor } from '../../interceptors/addAdminHeader.interceptor'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
|
||
describe.skip('ConversationLogicController', () => { | ||
let controller: ConversationLogicController; | ||
describe('TransformerController', () => { | ||
let controller: TransformerController; | ||
|
||
const mockTransformerData = { | ||
id: '123', | ||
createdAt: 1000, | ||
updatedAt: 1000, | ||
name: 'mockTransformerService', | ||
service: { create: 'create' }, | ||
tags: ['tag1', 'tag2'], | ||
config: { | ||
value: '123', | ||
}, | ||
}; | ||
|
||
const mockTransformerService = { | ||
create: jest.fn((data) => { | ||
return { | ||
id: '123', | ||
createdAt: 1000, | ||
updatedAt: 1000, | ||
name: data.name, | ||
service: { create: data.service }, | ||
tags: data.tags, | ||
config: data.config, | ||
}; | ||
}), | ||
|
||
findAll: jest.fn(() => { | ||
return [ | ||
{ | ||
...mockTransformerData, | ||
}, | ||
]; | ||
}), | ||
|
||
findOne: jest.fn((id) => { | ||
const res = { | ||
id, | ||
createdAt: 1000, | ||
updatedAt: 1000, | ||
name: 'mockTransformerService', | ||
service: { create: 'create' }, | ||
tags: ['tag1', 'tag2'], | ||
config: { | ||
value: '123', | ||
}, | ||
}; | ||
return { ...res }; | ||
}), | ||
|
||
update: jest.fn((id, data) => { | ||
return { | ||
id, | ||
createdAt: 1000, | ||
updatedAt: 1000, | ||
name: data.name, | ||
service: { create: data.service }, | ||
tags: data.tags, | ||
config: data.config, | ||
}; | ||
}), | ||
|
||
remove: jest.fn((id) => { | ||
return { | ||
id, | ||
}; | ||
}), | ||
}; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [ConversationLogicController], | ||
providers: [ConversationLogicService], | ||
}).compile(); | ||
controllers: [TransformerController], | ||
providers: [TransformerService], | ||
}) | ||
.overrideProvider(TransformerService) | ||
.useValue(mockTransformerService) | ||
.overrideInterceptor(AddAdminHeaderInterceptor) | ||
.useValue(createMock<AddAdminHeaderInterceptor>()) | ||
.overrideInterceptor(AddOwnerInfoInterceptor) | ||
.useValue(createMock<AddOwnerInfoInterceptor>()) | ||
.compile(); | ||
|
||
controller = module.get<TransformerController>(TransformerController); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should create a new transformer object', () => { | ||
const data = { | ||
name: 'mockTransformerService', | ||
service: 'create', | ||
tags: ['tag1', 'tag2'], | ||
config: { | ||
value: '123', | ||
}, | ||
}; | ||
expect(controller.create(data)).toEqual(mockTransformerData); | ||
expect(mockTransformerService.create).toBeCalled; | ||
}); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return the array of transformer objects', () => { | ||
expect(controller.findAll()).toEqual([{ ...mockTransformerData }]); | ||
expect(controller.findAll).toBeCalled; | ||
}); | ||
}); | ||
|
||
describe('findOne', () => { | ||
it('should return the specific transformer object', () => { | ||
expect(controller.findOne('123')).toEqual({ ...mockTransformerData }); | ||
expect(mockTransformerService.findOne).toBeCalled; | ||
}); | ||
}); | ||
|
||
controller = module.get<ConversationLogicController>(ConversationLogicController); | ||
describe('update', () => { | ||
it('should return the updated transformer object', () => { | ||
const mockResponse = { ...mockTransformerData }; | ||
mockResponse.name = 'updatedName'; | ||
expect( | ||
controller.update('123', { | ||
name: 'updatedName', | ||
service: 'create', | ||
tags: ['tag1', 'tag2'], | ||
config: { | ||
value: '123', | ||
}, | ||
}), | ||
).toEqual(mockResponse); | ||
expect(mockTransformerService.update).toBeCalled; | ||
}); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
describe('remove', () => { | ||
it('should successfully delete a transformer object', () => { | ||
const id = '123'; | ||
expect(controller.remove('123')).toEqual({ id }); | ||
expect(mockTransformerService.remove).toBeCalled; | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,18 +1,155 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserSegmentService } from './user-segment.service'; | ||
import { PrismaService } from '../../global-services/prisma.service'; | ||
|
||
describe.skip('UserSegmentService', () => { | ||
describe('UserSegmentService', () => { | ||
let service: UserSegmentService; | ||
|
||
const mockUserSegment = { | ||
id: '123', | ||
createdAt: 10000, | ||
updatedAt: 10000, | ||
name: 'mockUserSegment', | ||
all: { | ||
connect: { | ||
id: 7, | ||
}, | ||
}, | ||
byPhone: { | ||
connect: { | ||
id: 8, | ||
}, | ||
}, | ||
byId: { | ||
connect: { | ||
id: 9, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockUserSegmentService = { | ||
userSegment: { | ||
create: jest.fn(async (userSegment) => { | ||
return { | ||
id: '123', | ||
createdAt: 10000, | ||
updatedAt: 10000, | ||
name: userSegment.data.name, | ||
all: { | ||
connect: { | ||
id: 7, | ||
}, | ||
}, | ||
byPhone: { | ||
connect: { | ||
id: 8, | ||
}, | ||
}, | ||
byId: { | ||
connect: { | ||
id: 9, | ||
}, | ||
}, | ||
}; | ||
}), | ||
|
||
findUnique: jest.fn((filter) => { | ||
const resp = { ...mockUserSegment }; | ||
resp.id = filter.where.id; | ||
return resp; | ||
}), | ||
|
||
findMany: jest.fn().mockReturnValue([{ ...mockUserSegment }]), | ||
}, | ||
adapter: { | ||
update: jest.fn((payload) => { | ||
return { | ||
id: payload.where.id, | ||
createdAt: 10000, | ||
updatedAt: 10000, | ||
...payload.data, | ||
}; | ||
}), | ||
}, | ||
}; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UserSegmentService], | ||
providers: [ | ||
UserSegmentService, | ||
{ | ||
provide: PrismaService, | ||
useValue: mockUserSegmentService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<UserSegmentService>(UserSegmentService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
describe('create', () => { | ||
it('should successfully create a user segment', async () => { | ||
const userSegment = { | ||
name: 'mockUserSegment', | ||
all: 7, | ||
phone: 8, | ||
ID: 9, | ||
}; | ||
expect(await service.create(userSegment)).toEqual({ ...mockUserSegment }); | ||
expect(mockUserSegmentService.userSegment.create).toHaveBeenCalled; | ||
}); | ||
}); | ||
|
||
describe('findOne', () => { | ||
it('should return specific user info', () => { | ||
const resp = { ...mockUserSegment }; | ||
resp.id = '567'; | ||
expect(service.findOne('567')).toEqual({ ...resp }); | ||
expect(mockUserSegmentService.userSegment.findUnique).toHaveBeenCalled; | ||
}); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return array of all user segment object', () => { | ||
expect(service.findAll()).toEqual([{ ...mockUserSegment }]); | ||
expect(mockUserSegmentService.userSegment.findMany).toHaveBeenCalled; | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should successfully update user segment', () => { | ||
const resp = { ...mockUserSegment }; | ||
resp.name = 'updatedName'; | ||
expect( | ||
service.update('123', { | ||
name: 'updatedName', | ||
all: { | ||
connect: { | ||
id: 7, | ||
}, | ||
}, | ||
byPhone: { | ||
connect: { | ||
id: 8, | ||
}, | ||
}, | ||
byId: { | ||
connect: { | ||
id: 9, | ||
}, | ||
}, | ||
}), | ||
).toEqual({ ...resp }); | ||
expect(mockUserSegmentService.adapter.update).toHaveBeenCalled; | ||
}); | ||
}); | ||
|
||
describe('remove', () => { | ||
it('should remove user segment object', () => { | ||
const id = '123'; | ||
expect(service.remove('123')).toEqual( | ||
`This action removes a #${id} adapter`, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @1010varun this PR is supposed to contain test fixes for
user-segment.service
but it contains changes fortransformer.controller
as well which as addressed on this PR. Can you clean this PR up to only contain the necessary changes after rebasing from the latestdevelop
branch?