Skip to content

Commit

Permalink
Merge branch 'develop' into fix.one_signal_encode_external_id_in_endp…
Browse files Browse the repository at this point in the history
…oint
  • Loading branch information
anantjain45823 authored Feb 27, 2024
2 parents b1adfff + 4be2997 commit 11ed4e7
Show file tree
Hide file tree
Showing 25 changed files with 2,316 additions and 211 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ See the project's [README](README.md) for further information about working in t
- Include instructions on how to test your changes.
3. Your branch may be merged once all configured checks pass, including:
- A review from appropriate maintainers
4. Along with the PR in transformer raise a PR against [config-generator][config-generator] with the configurations.

## Committing

Expand Down
70 changes: 70 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@pyroscope/nodejs": "^0.2.6",
"@rudderstack/integrations-lib": "^0.2.4",
"@rudderstack/workflow-engine": "^0.7.2",
"@shopify/jest-koa-mocks": "^5.1.1",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^2.1.1",
Expand Down
186 changes: 186 additions & 0 deletions src/controllers/__tests__/delivery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import request from 'supertest';
import { createHttpTerminator } from 'http-terminator';
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import { applicationRoutes } from '../../routes';
import { NativeIntegrationDestinationService } from '../../services/destination/nativeIntegration';
import { ServiceSelector } from '../../helpers/serviceSelector';

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 getData = () => {
return { body: { JSON: { a: 'b' } }, metadata: [{ a1: 'b1' }], destinationConfig: { a2: 'b2' } };
};

describe('Delivery controller tests', () => {
describe('Delivery V0 tests', () => {
test('successful delivery', async () => {
const testOutput = { status: 200, message: 'success' };
const mockDestinationService = new NativeIntegrationDestinationService();
mockDestinationService.deliver = jest
.fn()
.mockImplementation((event, destinationType, requestMetadata, version) => {
expect(event).toEqual(getData());
expect(destinationType).toEqual('__rudder_test__');
expect(version).toEqual('v0');
return testOutput;
});
const getNativeDestinationServiceSpy = jest
.spyOn(ServiceSelector, 'getNativeDestinationService')
.mockImplementation(() => {
return mockDestinationService;
});

const response = await request(server)
.post('/v0/destinations/__rudder_test__/proxy')
.set('Accept', 'application/json')
.send(getData());

expect(response.status).toEqual(200);
expect(response.body).toEqual({ output: testOutput });

expect(response.header['apiversion']).toEqual('2');

expect(getNativeDestinationServiceSpy).toHaveBeenCalledTimes(1);
expect(mockDestinationService.deliver).toHaveBeenCalledTimes(1);
});

test('delivery failure', async () => {
const mockDestinationService = new NativeIntegrationDestinationService();
mockDestinationService.deliver = jest
.fn()
.mockImplementation((event, destinationType, requestMetadata, version) => {
expect(event).toEqual(getData());
expect(destinationType).toEqual('__rudder_test__');
expect(version).toEqual('v0');
throw new Error('test error');
});
const getNativeDestinationServiceSpy = jest
.spyOn(ServiceSelector, 'getNativeDestinationService')
.mockImplementation(() => {
return mockDestinationService;
});

const response = await request(server)
.post('/v0/destinations/__rudder_test__/proxy')
.set('Accept', 'application/json')
.send(getData());

const expectedResp = {
output: {
message: 'test error',
statTags: {
errorCategory: 'transformation',
},
destinationResponse: '',
status: 500,
},
};
expect(response.status).toEqual(500);
expect(response.body).toEqual(expectedResp);

expect(response.header['apiversion']).toEqual('2');

expect(getNativeDestinationServiceSpy).toHaveBeenCalledTimes(1);
expect(mockDestinationService.deliver).toHaveBeenCalledTimes(1);
});
});

describe('Delivery V1 tests', () => {
test('successful delivery', async () => {
const testOutput = { status: 200, message: 'success' };
const mockDestinationService = new NativeIntegrationDestinationService();
mockDestinationService.deliver = jest
.fn()
.mockImplementation((event, destinationType, requestMetadata, version) => {
expect(event).toEqual(getData());
expect(destinationType).toEqual('__rudder_test__');
expect(version).toEqual('v1');
return testOutput;
});
const getNativeDestinationServiceSpy = jest
.spyOn(ServiceSelector, 'getNativeDestinationService')
.mockImplementation(() => {
return mockDestinationService;
});

const response = await request(server)
.post('/v1/destinations/__rudder_test__/proxy')
.set('Accept', 'application/json')
.send(getData());

expect(response.status).toEqual(200);
expect(response.body).toEqual({ output: testOutput });

expect(response.header['apiversion']).toEqual('2');

expect(getNativeDestinationServiceSpy).toHaveBeenCalledTimes(1);
expect(mockDestinationService.deliver).toHaveBeenCalledTimes(1);
});

test('delivery failure', async () => {
const mockDestinationService = new NativeIntegrationDestinationService();
mockDestinationService.deliver = jest
.fn()
.mockImplementation((event, destinationType, requestMetadata, version) => {
expect(event).toEqual(getData());
expect(destinationType).toEqual('__rudder_test__');
expect(version).toEqual('v1');
throw new Error('test error');
});
const getNativeDestinationServiceSpy = jest
.spyOn(ServiceSelector, 'getNativeDestinationService')
.mockImplementation(() => {
return mockDestinationService;
});

const response = await request(server)
.post('/v1/destinations/__rudder_test__/proxy')
.set('Accept', 'application/json')
.send(getData());

const expectedResp = {
output: {
message: 'test error',
statTags: {
errorCategory: 'transformation',
},
status: 500,
response: [{ error: 'test error', metadata: { a1: 'b1' }, statusCode: 500 }],
},
};
expect(response.status).toEqual(200);
expect(response.body).toEqual(expectedResp);

expect(response.header['apiversion']).toEqual('2');

expect(getNativeDestinationServiceSpy).toHaveBeenCalledTimes(1);
expect(mockDestinationService.deliver).toHaveBeenCalledTimes(1);
});
});
});
Loading

0 comments on commit 11ed4e7

Please sign in to comment.