-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chandra shekar Varkala
committed
Feb 15, 2024
1 parent
9b7c034
commit e5f3aa8
Showing
8 changed files
with
221 additions
and
31 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
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
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,107 @@ | ||
import request from 'supertest'; | ||
import { createHttpTerminator } from 'http-terminator'; | ||
import Koa from 'koa'; | ||
import bodyParser from 'koa-bodyparser'; | ||
import { applicationRoutes } from '../../routes'; | ||
import { ServiceSelector } from '../../helpers/serviceSelector'; | ||
import { NativeIntegrationDestinationService } from '../../services/destination/nativeIntegration'; | ||
|
||
let server: any; | ||
const OLD_ENV = process.env; | ||
|
||
beforeAll(async () => { | ||
process.env = { ...OLD_ENV }; // Make a copy | ||
const app = new Koa(); | ||
app.use( | ||
bodyParser({ | ||
jsonLimit: '200mb', | ||
}), | ||
); | ||
applicationRoutes(app); | ||
server = app.listen(9090); | ||
}); | ||
|
||
afterAll(async () => { | ||
process.env = OLD_ENV; // Restore old environment | ||
const httpTerminator = createHttpTerminator({ | ||
server, | ||
}); | ||
await httpTerminator.terminate(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const getDeletionData = () => { | ||
return [ | ||
{ userAttributes: [{ a: 'b1' }], destType: '__rudder_test__' }, | ||
{ userAttributes: [{ a: 'b1' }], destType: '__rudder_test__' }, | ||
]; | ||
}; | ||
|
||
describe('Regulation controller tests', () => { | ||
describe('Delete users tests', () => { | ||
test('successful delete users request', async () => { | ||
const mockDestinationService = new NativeIntegrationDestinationService(); | ||
|
||
const expectedOutput = [{ statusCode: 400 }, { statusCode: 200 }]; | ||
|
||
mockDestinationService.processUserDeletion = jest | ||
.fn() | ||
.mockImplementation((reqs, destInfo) => { | ||
expect(reqs).toEqual(getDeletionData()); | ||
expect(destInfo).toEqual({ a: 'test' }); | ||
|
||
return expectedOutput; | ||
}); | ||
const getDestinationServiceSpy = jest | ||
.spyOn(ServiceSelector, 'getNativeDestinationService') | ||
.mockImplementation(() => { | ||
return mockDestinationService; | ||
}); | ||
|
||
const response = await request(server) | ||
.post('/deleteUsers') | ||
.set('Accept', 'application/json') | ||
.set('x-rudder-dest-info', '{"a": "test"}') | ||
.send(getDeletionData()); | ||
|
||
expect(response.status).toEqual(400); | ||
expect(response.body).toEqual(expectedOutput); | ||
|
||
expect(getDestinationServiceSpy).toHaveBeenCalledTimes(1); | ||
expect(mockDestinationService.processUserDeletion).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('delete users request failure', async () => { | ||
const mockDestinationService = new NativeIntegrationDestinationService(); | ||
|
||
mockDestinationService.processUserDeletion = jest | ||
.fn() | ||
.mockImplementation((reqs, destInfo) => { | ||
expect(reqs).toEqual(getDeletionData()); | ||
expect(destInfo).toEqual({ a: 'test' }); | ||
|
||
throw new Error('processUserDeletion error'); | ||
}); | ||
const getDestinationServiceSpy = jest | ||
.spyOn(ServiceSelector, 'getNativeDestinationService') | ||
.mockImplementation(() => { | ||
return mockDestinationService; | ||
}); | ||
|
||
const response = await request(server) | ||
.post('/deleteUsers') | ||
.set('Accept', 'application/json') | ||
.set('x-rudder-dest-info', '{"a": "test"}') | ||
.send(getDeletionData()); | ||
|
||
expect(response.status).toEqual(500); | ||
expect(response.body).toEqual([{ error: {}, statusCode: 500 }]); | ||
|
||
expect(getDestinationServiceSpy).toHaveBeenCalledTimes(1); | ||
expect(mockDestinationService.processUserDeletion).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.