-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from commercetools/order-syncer/integration-test
Order syncer IT
- Loading branch information
Showing
16 changed files
with
104 additions
and
54 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
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
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,3 +1,3 @@ | ||
export const MESSAGE_TYPE = ['OrderCreated']; | ||
export const CTP_ORDER_CHANGE_SUBSCRIPTION_KEY = | ||
'CTP_ORDER_CHANGE_SUBSCRIPTION_KEY'; | ||
'ct-connect-tax-integration-order-change-subscription'; |
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,5 +1,3 @@ | ||
export const HTTP_STATUS_SUCCESS_ACCEPTED = 202; | ||
export const HTTP_STATUS_SUCCESS_NO_CONTENT = 204; | ||
export const HTTP_STATUS_BAD_REQUEST = 400; | ||
export const HTTP_STATUS_RESOURCE_NOT_FOUND = 404; | ||
export const HTTP_STATUS_SERVER_ERROR = 500; |
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
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,8 @@ | ||
module.exports = { | ||
rootDir: '../../', | ||
displayName: 'Tests Javascript Application - Service', | ||
testMatch: ['**/test/integration/?(*.)+(spec|test).js?(x)'], | ||
testEnvironment: 'node', | ||
verbose: true, | ||
silent: true, | ||
}; |
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,60 @@ | ||
import { expect, describe, afterAll, it } from '@jest/globals'; | ||
import request from 'supertest'; | ||
import server from '../../src/index.js'; | ||
import { encodeJsonObject } from './utils/encoder.utils.js'; | ||
import { HTTP_STATUS_SUCCESS_ACCEPTED } from '../../src/constants/http.status.constants.js'; | ||
/** Reminder : Please put mandatory environment variables in the settings of your github repository **/ | ||
describe('Test sync.route.js', () => { | ||
it(`When resource identifier is absent in URL, it should returns 404 http status`, async () => { | ||
let response = {}; | ||
// Send request to the connector application with following code snippet. | ||
|
||
response = await request(server).post(`/`); | ||
expect(response).toBeDefined(); | ||
expect(response.statusCode).toEqual(404); | ||
}); | ||
|
||
it(`When payload body does not exist, it should returns 400 http status`, async () => { | ||
let response = {}; | ||
// Send request to the connector application with following code snippet. | ||
let payload = {}; | ||
response = await request(server).post(`/orderSyncer`).send(payload); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.statusCode).toEqual(HTTP_STATUS_SUCCESS_ACCEPTED); | ||
}); | ||
|
||
it(`When payload body exists without correct order ID, it should returns 404 http status`, async () => { | ||
let response = {}; | ||
// Send request to the connector application with following code snippet. | ||
// Following incoming message data is an example. Please define incoming message based on resources identifer in your own Commercetools project | ||
const incomingMessageData = { | ||
notificationType: 'Message', | ||
resource: { typeId: 'order', id: 'dummy-product-id' }, | ||
type: 'OrderCreated', | ||
resourceUserProvidedIdentifiers: { orderNumber: 'dummy-order-number' }, | ||
version: 11, | ||
oldVersion: 10, | ||
modifiedAt: '2023-09-12T00:00:00.000Z', | ||
}; | ||
|
||
const encodedMessageData = encodeJsonObject(incomingMessageData); | ||
let payload = { | ||
message: { | ||
data: encodedMessageData, | ||
}, | ||
}; | ||
response = await request(server).post(`/orderSyncer`).send(payload); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.statusCode).toEqual(HTTP_STATUS_SUCCESS_ACCEPTED); | ||
}); | ||
|
||
afterAll(() => { | ||
// Enable the function below to close the application on server once all test cases are executed. | ||
|
||
if (server) { | ||
server.close(); | ||
} | ||
}); | ||
}); |
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,9 @@ | ||
const encodeString = (message) => { | ||
const buff = Buffer.from(message); | ||
return buff.toString('base64').trim(); | ||
}; | ||
|
||
export const encodeJsonObject = (messageBody) => { | ||
const message = JSON.stringify(messageBody); | ||
return encodeString(message); | ||
}; |
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