2025-02-20 - Integration Test examples
(Redirected from Integration Test Examples)
Jump to navigation
Jump to search
Service - Integration Test Config
Overview
- The example of propeerties in resources.json, events.json and tests.json for upload to S3 bucket
- Integration Test Config for config of each property in these files
resources.json
{
"Lambda":{
"{FunctionNameHdrSqs}":{
"localLacation":"/src/FunctionNameHdrSqs.js",
"localHandler":"main",
"functionName":"FunctionNameHdrSqs" // FunctionName is full name of function after deploy
},
"ProcessComplexFilterHdrSqs":{
"localLacation":"/src/ProcessComplexFilterHdrSqs.js",
"localHandler":"main",
"functionName":"ProcessComplexFilterHdrSqs"
},
...
},
"Dynamodb": {
"filterMain":{
"tableName":"filterMain"
},
"tableNameBB":{
"tableName":"tableNameBB"
},
...
}
}
events.json
- file events.js is have eventTag (inputEventTag,outputEventTag,dynamodbTag)
- How to create name eventTag
- Example case : "test in service complexFilter functionname ProcessComplexFilter case element type is logical basic".
- How to create name eventTag
- inputEventTag
- {serviceName}_{functionName}_{caseTest}
- outputEventTag
- output_{inputEventTag}
- dynamodbTag
- {inputEventTag}__Dynamodb__{action*}_{tableName}
- {action} is only put or update, and in case of update must only test the last step of update
// Layout of file events.json
{
input:{},
output:{},
dynamodb:{} // optional
}
// An example of naming an eventTag for each event
{
"Complexfilter_ProcessComplexfilter_logical_basic": {}, // for input
"Output_Complexfilter_ProcessComplexfilter_logical_basic": {}, // for output
"Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain": {} // for dynamodb
}
Sns
- if initeage stage set
"snsSqsTrigger":true
// An example input and output event of Sns
{
"LambdaFunctionHdrSqs_input__pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
},
"propertyB":{
"forStageMatching":true,
"properties":{
"propertyB1":{
"forStageMatching":true,
"value":"valuePropertyB1"
}
}
},
"propertyC":{
"eventValue":[
"valuePropertyC1",
"valuePropertyC2",
"valuePropertyC3"
]
}
},
"snsSqsTrigger":true,
"messageAttributes":{
"forStageMatching":true,
"properties":{
"msgTag":{
"forStageMatching":true,
"value":"msgTag"
},
"propertyD":{
"forStageMatching":true,
"value":"valuePropertyD"
}
}
}
},
{
"output_LambdaFunctionHdrSqs_pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
}
}
}
}
}
- snsSqsTrigger = true
- for initialStage of sns
- messageAttributes is optional
Dsq
- if initeage stage set
"DirectSqs":true
// An example input and output event of Direct Sqs
{
"LambdaFunctionHdrDsq_input__pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
},
"propertyB":{
"forStageMatching":true,
"properties":{
"propertyB1":{
"forStageMatching":true,
"value":"valuePropertyB1"
}
}
},
"propertyC":{
"eventValue":[
"valuePropertyC1",
"valuePropertyC2",
"valuePropertyC3"
]
}
},
"DirectSqs":true,
"messageAttributes":{
"forStageMatching":true,
"properties":{
"msgTag":{
"forStageMatching":true,
"value":"msgTag"
},
"propertyD":{
"forStageMatching":true,
"value":"valuePropertyD"
}
}
}
},
{
"output_LambdaFunctionHdrDsq_pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
}
}
}
}
}
- DirectSqs = true
- for initialStage of Dsq
- messageAttributes is optional
Invoke
{
"LambdaFunctionHdrInv_input__pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
},
"propertyB":{
"forStageMatching":true,
"properties":{
"propertyB1":{
"forStageMatching":true,
"value":"valuePropertyB1"
}
}
}
}
},
{
"output_LambdaFunctionHdrInv_pass":{
"forStageMatching":true,
"properties":{
"propertyA":{
"forStageMatching":true,
"value":"valueProperty1"
}
}
}
}
}
API
// An example input and output event of API
{
"LambdaFunctionHdrApi_input__pass_notTestAuthorizer": {
"forstageMatvhing": true,
"properties": {
"body": {
"properties": {
"propertyA": {
"testValueMatches": false,
"value": "valueProperty1",
},
"propertyB": {
"properties": {
"propertyB1": {
"value": "valuePropertyB1",
}
}
},
"propertyC": {
"eventValue": [
"valuePropertyC1",
"valuePropertyC2",
"valuePropertyC3",
]
},
...
}
}
}
},
"Output_LambdaFunctionHdrApi_input__pass_notTestAuthorizer": {
"properties": {
"body": {
"properties": {
"propertyA": {
"testValueMatches": false,
"value": "valueProperty1"
},
...
}
}
}
}
}
Dynamodb
// An example event of Dynamodb //optional
{
{inputEventTag}__dynamodb_{action}_{tablename}: { // eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain"
"forStageMatching": true,
"properties": {
"filterMainUniqueRequestId": {
"testValueMatches": true,
"value": "bbc4f4a9-2032-4dec-9129-8c7d169fecc5"
},
"filterObject": {
"forStageMatching": true,
"properties": {
"logicalType": {
"value": "partitionKey"
},
"comparison": {
"value": "equals"
},
"type": {
"value": "logical"
},
"partitionKey": {
"forStageMatching": true,
"value": "mockIntegratioTestCPF"
}
}
},
"filterMainExpiryTime": {
"testValueMatches": true,
"value": 1731980802858
},
"filterMainStatus": {
"forStageMatching": true,
"value": "processing"
},
"createTime": {
"testValueMatches": true,
"value": 1731894402678
},
"objType": {
"forStageMatching": true,
"properties": {
"serviceTag": {
"forStageMatching": true,
"value": "IntTesting"
},
"objectType": {
"forStageMatching": true,
"value": "TestRecord"
}
}
}
},
"keyValues": {
"filterMainId": "4865d2451a621cb7f71225cfabf2df4f98e20801",
"objTypeId": "cdb170690571df7522b3850920fce02507c077ee"
}
}
}
- partition key: filterMainId
- sort key: objTypeId
NoRetryError
// An example event of NoRetryError output
{
Output_{inputEvenTag}: { // eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic"
"forStageMatching": true,
"properties": {
"errorMessage": {
"value": "Not found schema of {serviceTag:TestGraphHandler, objectType:notFoundObjType}"
}
}
}
}
tests.json
- file tests.js have integrationTestTag
- integrationTestTag is Test_{inputEventTag}
- - multiple stage test integrationTest_{inputEventTag}
dynamodb
[
{
"integrationTestTag":"test_S3_ByDev",
"productionSafe":false,
"errorIfStageUnderfined":false,
"errorIfInvokeUnderfined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"Complexfiter_ProcessComplexfiter_logical_basic",
"serviceTag":"IntCPF",
"resourceType":"Lambda",
"resourceName":"ProcessComplexFilterHdrSqs",
"snsServiceName":"IntCPF",
"snsTopic":"InProcessComplexFilter",
"outputEventTag":"Output_Complexfiter_ProcessComplexfiter_logical_basic",
"dynamodbOutputEventIdentifiers":[
{
"serviceTag": "IntCPF",
"resourceName": "FilterMain",
"eventTag": "testS3_integrationtest_complexfiter_Dynamodb_updateItem_FilterMain"
}
]
}
]
}
]
initalStage
- add initial stage
- "initialStage":true
Sns
[
{
"integrationTestTag":"test_S3_ByDev",
"productionSafe":false,
"errorIfStageUnderfined":false,
"errorIfInvokeUnderfined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"Complexfiter_ProcessComplexfiter_logical_basic",
"serviceName":"IntCPF",
"resourceType":"Lambda",
"resourceName":"ProcessComplexFilterHdrSqs",
"snsServiceName":"IntCPF",
"snsTopic":"InProcessComplexFilter",
"outputEventTag":"Output_Complexfiter_ProcessComplexfiter_logical_basic"
}
]
}
]
- If stage test is sns but is not initial stage not set property snsServiceName and sns Topic.
Dsq
[
{
"integrationTestTag":"test_S3_ByDev_Dsq",
"productionSafe":false,
"errorIfStageUnderfined":false,
"errorIfInvokeUnderfined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"Locations_ProcessLocationNodeSomting_casenotHaveData",
"serviceName":"Locations",
"resourceType":"Lambda",
"resourceName":"ProcessLocationNodeSomtingHdrDsq",
"outputEventTag":"Output_Locations_ProcessLocationNodeSomting_casenotHaveData"
}
]
}
]
Invoke
single stage
[{
"integrationTestTag":"LambdaFunctionHdrInv__pass",
"productionSafe":false,
"errorIfStageUndefined":false,
"errorIfInvokeUndefined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"LambdaFunctionHdrInv_input__pass",
"serviceName":"ServiceTemplate",
"resourceType":"Lambda",
"resourceName":"LambdaFunctionHdrInv",
"outputEventTag":"LambdaFunctionHdrInv_output__pass"
}
]
}]
invoke multiple stage
- Each stage test can invoke multiple lambda by use "eventStage Tag" point to stage for test integration test.
[{
"integrationTestTag":"LambdaFunctionHdrInv_invokes__pass",
"productionSafe":false,
"errorIfStageUndefined":false,
"errorIfInvokeUndefined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"LambdaFunctionHdrInv_input__pass",
"serviceName":"ServiceTemplate",
"resourceType":"Lambda",
"resourceName":"LambdaFunctionHdrInv",
"outputEventTag":"LambdaFunctionHdrInv_output__pass",
"invokes":[
{
"eventStageTag":"service_invokesB__pass"
},
{
"eventStageTag":"service_invokesD__pass"
}
]
},
{
"eventStageTag":"service_invokesB__pass",
"inputEventTag":"input_service_invokes__pass",
"serviceName":"ServiceTemplate_B",
"resourceType":"Lambda",
"resourceName":"LambdaFunction_B_HdrInv",
"outputEventTag":"output_service_invokes__pass"
},
{
"eventStageTag":"service_invokesD__pass",
"inputEventTag":"input_service_invokesD__pass",
"serviceName":"ServiceTemplate_D",
"resourceType":"Lambda",
"resourceName":"LambdaFunction_D_HdrInv",
"outputEventTag":"output_service_invokesD__pass"
}
]
}]
Api
[
{
"integrationTestTag":"LambdaFunctionHdrApi__pass",
"productionSafe":false,
"errorIfStageUndefined":false,
"errorIfInvokeUndefined":false,
"stages":[
{
"initialStage":true,
"inputEventTag":"LambdaFunctionHdrApi_input__pass",
"serviceName":"ServiceTemplate",
"resourceType":"Lambda",
"resourceName":"LambdaFunctionHdrApi",
"outputEventTag":"LambdaFunctionHdrApi_output__pass"
}
]
}
]
RefreshSeedData
Seed data for test case, can generate seed data by use this setting. Process refresh seed data first step delete all seed data after that create all seed data.
[
{
"integrationTestTag": "Test_mackTestLogic_refreceSeedData_DeleteIdentifier",
"productionSafe": false,
"errorIfStageUnderfined": false,
"errorIfInvokeUnderfined": false,
"dynamoDBSeedDataTags": [
"seedDynamodb_abc_ver2"
],
"graphSeedDataTags": [
"seedData_testTag_GG"
],
"stages": [
//...
]
}
]
- create file dynamoDBSeedDataTags.json and graphSeedDataTags.json
- (Admin)This tag save file in floder seedData_config
- (Other dev)Save in s3 in folder test_config
dynamoDBSeedDataTags
- If set tag in this setting integrationtest is generate seed data. in storage resource dynammodb.
{
"seedDynamodb_abc_ver2": [ // seedDataTag
{
"tableName": "DelivMethodSTDTestLogicalResultsData", // servcieTag+stage+tablename
"partitionKey": "logicalResultId",
"sortKey": "identifiersId",
"datas": [
{
"logicalResultId": "eeeeeeeeee4",
"identifiersId": "lllll123456"
},
{
"logicalResultId": "eeeeeeeeee4",
"identifiersId": "lllll777777"
}
]
},
{
"tableName": "MLocationsTestFloatingRelationships",// servcieTag+stage+tablename
"partitionKey": "importBatchId",
"sortKey": "identifierRelationshipsId",
"datas": [
{
"importBatchId": "2-uuuuuuuuuuuuuu",
"identifierRelationshipsId": "lllll123456"
},
{
"importBatchId": "2-uuuuuuuuuuuuuu",
"identifierRelationshipsId": "lllll777777"
},
{
"importBatchId": "2-uuuuuuuuuuuuuu",
"identifierRelationshipsId": "lllll99999999"
}
]
},
{
"tableName": "MLocationsTestFindDataMain",
"partitionKey": "findDataId",
"datas": [
{
"findDataId": "111111"
},
{
"findDataId": "22222"
},
{
"findDataId": "333333"
}
]
}
]
}
graphSeedDataTags
- If set tag in this setting integrationtest is generate seed data. in storage resource graphHanler.
{
"seedData_testTag_GG": [ // seedDataTag
{
"nodes": [
{
"nodeLabels": [
"SellOfferPlan_sellOfferPlanDeliveryMethodLink"
],
"objectDetail": {
"identifiers": {
"sellOfferPlanDeliveryMethodLinkId": "minttestrefreshSeedData_01"
},
"fields": {
"productId": "ddddd",
"price": 9999
}
}
},
{
"nodeLabels": [
"servcieMintTest_shoppingMall"
],
"objectDetail": {
"identifiers": {
"shoppingMallId": "minttestrefreshSeedData_shoppingMallId"
},
"fields": {
"name": "hotpot-man",
"totalPrice": 500
}
}
},
{
"nodeLabels": [
"servcieMintTest_shoppingMallCalculateSetting"
],
"objectDetail": {
"identifiers": {
"versionedDataId": "minttestrefreshSeedData_versionedDataId"
},
"fields": {
"addToCalculatedValuePerOrder": 10,
"addToRateTableValuePerOrder": 77
}
}
}
],
"relationships": [
{
"fromObject": {
"nodeLabel": "SellOfferPlan_sellOfferPlanDeliveryMethodLink",
"identifiers": {
"sellOfferPlanDeliveryMethodLinkId": "minttestrefreshSeedData_01"
}
},
"toObject": {
"nodeLabel": "servcieMintTest_shoppingMall",
"identifiers": {
"shoppingMallId": "minttestrefreshSeedData_shoppingMallId"
}
},
"relationships": [
{
"relTypeConcat": "SellOfferPlan_hasCCCCCCC",
"relId": "uuid-4s56df74s9df79w-w6de4f5w689ef"
}
]
},
{
"fromObject": {
"nodeLabel": "servcieMintTest_shoppingMall",
"identifiers": {
"shoppingMallId": "minttestrefreshSeedData_shoppingMallId"
}
},
"toObject": {
"nodeLabel": "servcieMintTest_shoppingMallCalculateSetting",
"identifiers": {
"versionedDataId": "minttestrefreshSeedData_versionedDataId"
}
},
"relationships": [
{
"relTypeConcat": "servcieMintTest_shoppingMall_currentShoppingMallCalculateSetting",
"relId": "uuid-s122df5-s21df",
"relationshipProperty": {
"timeStamp": 1234567879,
"statusName": true
}
},
{
"relTypeConcat": "servcieMintTest_shoppingMall_hasShoppingMallCalculateSetting",
"relId": "uuid-77777-99999",
"relationshipProperty": {
"statusName": true
}
}
]
}
]
}
],
"seedData_testTag_ABC": [
{
"objType": {
"objectType": "productAttributeLink",
"serviceTag": "ProductAttribute"
},
"objInstanceFull": {
"identifiers": {
"productAttributeLinkId": "f90b57ca8b2fe1a83459d57da038cf50fb6d40e6"
},
"fields": {}
},
"relationships": [
{
"relType": {
"serviceTag": "ProductAttribute",
"relationshipTag": "hasProductAttributeLink"
},
"relationshipDirection": "to",
"targetObjType": {
"serviceTag": "ProductStandard",
"objectType": "productStandard"
},
"targetIdentifiers": {
"productId": "f526a367a2b66cb0f37ca61b6c43f419929f521d"
},
"relationshipProperties": {}
},
{
"relType": {
"serviceTag": "ProductAttribute",
"relationshipTag": "isProductAttribute"
},
"relationshipDirection": "from",
"targetObjType": {
"serviceTag": "ProductAttribute",
"objectType": "productAttribute"
},
"targetIdentifiers": {
"productAttributeId": "f4bf7a078071d54036656df544197ba638bc3a68"
},
"relationshipProperties": {}
}
]
},
{
"objType": {
"objectType": "productAttributeLink",
"serviceTag": "ProductAttribute"
},
"objInstanceFull": {
"identifiers": {
"productAttributeLinkId": "f90b57ca8b2fe1a83459d57da038cf50fb6d40e6"
},
"fields": {}
},
"relationships": []
}
],
"seedData_testTag_LL": []
}
- seedDataTag must be unique
- canbe share seed data for other test by seed data tag.
GenerateSeedData
- Integrationtest must be delete identifier every time before test.
- Set 'generatedSeedData' in file tests.json case by case of stage eg: stages[0] create identifier is randomOnCreate will set 'generatedSeedData' and stages[1] create relationship is randomOnCreate(It is usually random, except in the case of relationship version) set generatedSeedData this stages[1].
- How to delete case identifier rendomOnCreate?: set in stage use setting generateSeedData "randomOnCreateIdentifier"
- 3 case
- 1.randomOnCreateIdentifier
- 2.notRandomOnIdentifier
- 3.relationships
randomOnCreateIdentifier
[
{
"integrationTestTag": "Test_MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"productionSafe": false,
"errorIfStageUnderfined": false,
"errorIfInvokeUnderfined": false,
"dynamoDBSeedDataTags": [
"seedDynamodb_abc_ver2"
],
"graphSeedDataTags": [
"seedData_testTag_GG"
],
"stages": [
{
"initialStage": true,
"inputEventTag": "MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"serviceTag": "MLocations",
"resourceType": "Lambda",
"resourceName": "CreateHdrSqs",
"snsServiceName": "MLocations",
"snsTopic": "Create_In",
"generatedSeedData": {
"randomOnCreateIdentifier": [
{
"objType": {
"serviceTag": "MLocations",
"objectType": "Member"
},
"identifierValue": "Jaya-member-001"
}
]
}
}
]
}
]
notRandomOnIdentifier
[
{
"integrationTestTag": "Test_MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"productionSafe": false,
"errorIfStageUnderfined": false,
"errorIfInvokeUnderfined": false,
"dynamoDBSeedDataTags": [
"seedDynamodb_abc_ver2"
],
"graphSeedDataTags": [
"seedData_testTag_GG"
],
"stages": [
{
"initialStage": true,
"inputEventTag": "MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"serviceTag": "MLocations",
"resourceType": "Lambda",
"resourceName": "CreateHdrSqs",
"snsServiceName": "MLocations",
"snsTopic": "Create_In",
"generatedSeedData": {
"notRandomOnIdentifier": [
{
"objType": {
"serviceTag": "gggg",
"objectType": "ssssss"
},
"identifiers": {
"topId": "123456"
}
}
]
}
}
]
}
]
relationships
[
{
"integrationTestTag": "Test_MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"productionSafe": false,
"errorIfStageUnderfined": false,
"errorIfInvokeUnderfined": false,
"dynamoDBSeedDataTags": [
"seedDynamodb_abc_ver2"
],
"graphSeedDataTags": [
"seedData_testTag_GG"
],
"stages": [
{
"initialStage": true,
"inputEventTag": "MLocation_CreateHdrSqs__case_NodeVersionData_Jaya",
"serviceTag": "MLocations",
"resourceType": "Lambda",
"resourceName": "CreateHdrSqs",
"snsServiceName": "MLocations",
"snsTopic": "Create_In",
"generatedSeedData": {
"relationships": [
{
"relType": {
"serviceTag": "PaymentMethodGeneric",
"relationshipTag": "disabledPaymentMethodGenericPropertyValue"
},
"relId": "f4f73de7-647c-4b3b-8043-87cc002f361a"
}
]
}
}
]
}
]
transformProperties
-function change paramiter to use integrationtest.
const { error } = require("console");
function transformProperties(input) {
if (Array.isArray(input)) {
// If value is an array
return { eventValue: input };
} else if (input === undefined) {
return { value: "undefined" };
} else if (typeof input === "object"
// && input !== null
) {
// If value is an object
if (input === null) {
return { value: input };
// If object is empty, return "value: {}"
}
else if (Object.keys(input).length === 0) {
return { properties: { value: {} } };
}
// If object is not empty, recursively process its properties
const transformedObject = {};
for (const key in input) {
if (key === "properties") {
transformedObject[key] = transformProperties(input[key]);
}
transformedObject[key] = transformProperties(input[key]);
}
return { properties: transformedObject };
} else if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
// If value is a string or number
return {
value: input
};
} else {
// If value is something else (e.g., null or undefined), return it as is
return input;
}
}
let input = {
filterMainId: '6a10498096377d3cad76ecb8a9f7438ef5425934',
filterObject: {
type: 'logical',
logicalType: 'partitionKey',
partitionKey: 'mockForTestGreaterThanOrEqual',
sortKey: '5',
comparison: 'greaterThan'
}
}
let output = transformProperties(input)
// console.log(JSON.stringify(output, null, 2))
console.log(JSON.stringify(output, null, 2))