-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create sample test cases in incremental-updater module
- Loading branch information
1 parent
7e10d1a
commit 455ee1a
Showing
7 changed files
with
510 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: [['@babel/preset-env', {targets: {node: 'current'}}]], | ||
}; |
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 = { | ||
displayName: 'Tests Javascript Application - Service', | ||
moduleDirectories: ['node_modules', 'src'], | ||
testMatch: ['**/tests/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'], | ||
testEnvironment: 'node', | ||
verbose: true, | ||
silent: true, | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,65 @@ | ||
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'; | ||
|
||
/** Reminder : Please put mandatory environment variables in the settings of your github repository **/ | ||
describe('Test event.controller.js', () => { | ||
const storeKey = 'MY_STORE_KEY'; // Specify the key of Commercetools Store for product synchronization | ||
|
||
it(`POST /`, async () => { | ||
let response = {}; | ||
// Send request to the connector application with following code snippet. | ||
|
||
response = await request(server).post(`/`); | ||
|
||
expect(response).toBeDefined(); | ||
}); | ||
|
||
it(`POST /deltaSync with empty payload`, async () => { | ||
let response = {}; | ||
// Send request to the connector application with following code snippet. | ||
let payload = {}; | ||
response = await request(server).post(`/deltaSync`).send(payload); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.statusCode).toEqual(400); | ||
}); | ||
|
||
it(`POST /deltaSync with correct message in payload body`, 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: 'ResourceUpdated', | ||
projectKey: 'connect-search-template', | ||
resource: { typeId: 'product', id: 'dummy-product-id' }, | ||
resourceUserProvidedIdentifiers: { | ||
key: 'dummy-product-key', | ||
slug: { 'de-DE': 'dummy-product-slut' }, | ||
}, | ||
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(`/deltaSync`).send(payload); | ||
|
||
expect(response).toBeDefined(); | ||
expect(response.statusCode).toEqual(204); | ||
}); | ||
|
||
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); | ||
}; |