mirror of
https://github.com/LukeHagar/developer.sailpoint.com.git
synced 2025-12-08 12:27:47 +00:00
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
// Import getByIdHandler function from get-by-id.mjs
|
|
import { getByIdHandler } from '../../../src/handlers/get-by-id.mjs';
|
|
// Import dynamodb from aws-sdk
|
|
import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';
|
|
import { mockClient } from "aws-sdk-client-mock";
|
|
|
|
// This includes all tests for getByIdHandler()
|
|
describe('Test getByIdHandler', () => {
|
|
const ddbMock = mockClient(DynamoDBDocumentClient);
|
|
|
|
beforeEach(() => {
|
|
ddbMock.reset();
|
|
});
|
|
|
|
// This test invokes getByIdHandler() and compare the result
|
|
it('should get item by id', async () => {
|
|
const item = { id: 'id1' };
|
|
|
|
// Return the specified value whenever the spied get function is called
|
|
ddbMock.on(GetCommand).resolves({
|
|
Item: item,
|
|
});
|
|
|
|
const event = {
|
|
httpMethod: 'GET',
|
|
pathParameters: {
|
|
id: 'id1'
|
|
}
|
|
};
|
|
|
|
// Invoke getByIdHandler()
|
|
const result = await getByIdHandler(event);
|
|
|
|
const expectedResult = {
|
|
statusCode: 200,
|
|
headers: {
|
|
"Access-Control-Allow-Headers" : "Content-Type",
|
|
"Access-Control-Allow-Origin": "*",
|
|
"Access-Control-Allow-Methods": "OPTIONS,POST,GET"
|
|
},
|
|
body: JSON.stringify(item)
|
|
};
|
|
|
|
// Compare the result with the expected result
|
|
expect(result).toEqual(expectedResult);
|
|
});
|
|
});
|
|
|