Skip to content

Commit

Permalink
SK-1372 added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
skyflow-bharti committed Jan 18, 2024
1 parent 9b05e51 commit b9169bd
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/core-utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,16 @@ export const insertDataInCollect = async (
rootResolve(insertResponse);
},
(rejectedResult) => {
rootReject(rejectedResult);
rootReject({
errors: [
{
error: {
code: rejectedResult?.error?.code,
description: rejectedResult?.error?.description,
},
},
],
});
}).catch((err) => {
rootReject(err);

Check warning on line 300 in src/core-utils/collect.ts

View check run for this annotation

Codecov / codecov/patch

src/core-utils/collect.ts#L300

Added line #L300 was not covered by tests
});
Expand Down Expand Up @@ -341,7 +350,7 @@ export const updateRecordsBySkyflowID = async (
});

if (errorsResponse.length === 0) {
rootResolve(recordsResponse);
rootResolve({ records: recordsResponse });
} else if (recordsResponse.length === 0) rootReject({ errors: errorsResponse });
else rootReject({ records: recordsResponse, errors: errorsResponse });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class SkyflowFrameController {
body: { ...requestBody },
requestMethod: 'POST',
url:
`vault/v1/vaults/${
`${this.#client.config.vaultURL}/v1/vaults/${
this.#client.config.vaultID}`,
headers: {
Authorization: `Bearer ${authToken}`,
Expand Down
166 changes: 157 additions & 9 deletions tests/core/internal/iframe-form/iframe-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ const records = {
},
],
},
continueOnError: false
};

const clientObj1 = {
config: {},
request: jest.fn(() => Promise.reject({errors:[{ error : {code:404,description:"Not Found"}}]})),
request: jest.fn(() => Promise.reject({ error : {code:404,description:"Not Found"}})),
toJSON: jest.fn(() => ({
config: {},
metaData: {
Expand Down Expand Up @@ -458,6 +459,44 @@ const data = {
upsert: [{ table: '', column: ' ' }],
continueOnError: false
}
const data4 = {
additionalFields: {
records: [{
table: "pii_fields",
fields: {
cvv: '123',
name:'name',
skyflowID: 'ghgjhjh2',
}
}, {
table: 'table',
fields: {
name: 'joey'
}
}]
},
tokens: true,
continueOnError: true
}
const data5 = {
additionalFields: {
records: [{
table: "pii_fields",
fields: {
cvv: '123',
name:'name',
skyflowID: 'ghgjhjh2',
}
}, {
table: 'table',
fields: {
name: 'joey'
}
}]
},
tokens: false,
continueOnError: true
}
const data2 = {
additionalFields: {
records: [{
Expand Down Expand Up @@ -544,6 +583,53 @@ const insertResponse = {
}
]
}
const insertResponse2 = {
"vaultID": "<VaultID>",
"responses": [
{
"Body": {
"records": [
{
"skyflow_id": "ghgjhjh2",
"tokens": {
"card_number": "token",
"cvv": "token",
"expiry_date": "token",
"name": "token",
}
},
]
},
"Status": 200,
},
{
"Body": {
"error": "Invalid field present in JSON card_numbe"
},
"Status": 400
},
]
}
const data6 = {
additionalFields: {
records: [{
table: "pii_fields",
fields: {
cvv: '123',
name:'name',
skyflowID: 'ghgjhjh2',
}
}, {
table: 'table',
fields: {
name: 'joey'
}
}]
},
tokens: false,
upsert: [{ table: '', column: ' ' }],
continueOnError: false
}

export const fileResponse = {
"fileUploadResponse": [
Expand Down Expand Up @@ -578,6 +664,17 @@ const clientObj = {
}
}))
}
const clientObj2 = {
config: {},
request: jest.fn(() => Promise.resolve(insertResponse2)),
toJSON: jest.fn(() => ({
config: {},
metaData: {
uuid: ''
}
}))
}


describe('test iframeForm collect method', () => {

Expand Down Expand Up @@ -645,7 +742,7 @@ describe('test iframeForm collect method', () => {
tokenizationCb(data, cb3)

setTimeout(() => {
expect(cb3.mock.calls[0][0].records.length).toBe(1);
expect(cb3.mock.calls[0][0].records.length).toBe(2);
}, 1000)

element.fieldName = 'col';
Expand Down Expand Up @@ -726,7 +823,7 @@ describe('test iframeForm collect method', () => {
tokenizationCb(data, cb3)

setTimeout(() => {
expect(cb3.mock.calls[0][0].records.length).toBe(1);
expect(cb3.mock.calls[0][0].records.length).toBe(2);
}, 1000)

element.fieldName = 'col';
Expand Down Expand Up @@ -792,23 +889,59 @@ describe('test iframeForm collect method', () => {
const cb2 = jest.fn();
tokenizationCb(data, cb2);
setTimeout(() => {
expect(cb2.mock.calls[0][0].records.length).toBe(1);
expect(cb2.mock.calls[0][0].records.length).toBe(2);
expect(cb2.mock.calls[0][0].records[0].table).toBe('table');
expect(Object.keys(cb2.mock.calls[0][0].records[0].fields).length).toBe(5);
done()
}, 1000)
})
let clientObj1 = {
config: {},
request: jest.fn(() => Promise.reject({errors:[{ error : {code:404,description:"Not Found"}}]})),
request: jest.fn(() => Promise.reject({ error : {code:404,description:"Not Found"}})),
toJSON: jest.fn(() => ({
config: {},
metaData: {
uuid: ''
}
}))
}
test('ererr', (done) => {
test('error insert case when continue error is true', (done) => {
const form = new IFrameForm("controllerId", "", "ERROR");
form.setClient(clientObj2)
form.setClientMetadata(metaData)
form.setContext(context)

const tokenizationEvent = on.mock.calls.filter((data) => data[0] === ELEMENT_EVENTS_TO_IFRAME.TOKENIZATION_REQUEST + 'controllerId');
const tokenizationCb = tokenizationEvent[0][1];
const cb2 = jest.fn();
tokenizationCb(data4, cb2);
setTimeout(() => {
expect(cb2.mock.calls[0][0].error).toBeDefined();
done()
}, 1000)
form.tokenize(data4).then().catch( err => {
expect(err).toBeDefined();
})
})
test('error insert case when continue error is true and token is false', (done) => {
const form = new IFrameForm("controllerId", "", "ERROR");
form.setClient(clientObj2)
form.setClientMetadata(metaData)
form.setContext(context)

const tokenizationEvent = on.mock.calls.filter((data) => data[0] === ELEMENT_EVENTS_TO_IFRAME.TOKENIZATION_REQUEST + 'controllerId');
const tokenizationCb = tokenizationEvent[0][1];
const cb2 = jest.fn();
tokenizationCb(data5, cb2);
setTimeout(() => {
expect(cb2.mock.calls[0][0].error).toBeDefined();
done()
}, 1000)
form.tokenize(data4).then().catch( err => {
expect(err).toBeDefined();
})
})
test('error insert case when continue error is false', (done) => {
const form = new IFrameForm("controllerId", "", "ERROR");
form.setClient(clientObj1)
form.setClientMetadata(metaData)
Expand All @@ -826,6 +959,24 @@ describe('test iframeForm collect method', () => {
expect(err).toBeDefined();
})
})
test('error insert case when continue error is false and token is false', (done) => {
const form = new IFrameForm("controllerId", "", "ERROR");
form.setClient(clientObj)
form.setClientMetadata(metaData)
form.setContext(context)

const tokenizationEvent = on.mock.calls.filter((data) => data[0] === ELEMENT_EVENTS_TO_IFRAME.TOKENIZATION_REQUEST + 'controllerId');
const tokenizationCb = tokenizationEvent[0][1];
const cb2 = jest.fn();
tokenizationCb(data6, cb2);
setTimeout(() => {
expect(cb2.mock.calls[0][0].records).toBeDefined();
done()
}, 1000)
form.tokenize(data).then().catch( err => {
expect(err).toBeDefined();
})
})
test('success', (done) => {
const form = new IFrameForm("controllerId", "", "ERROR");
form.setClient(clientObj1)
Expand Down Expand Up @@ -880,7 +1031,6 @@ describe('test iframeForm collect method', () => {
const cb2 = jest.fn();
tokenizationCb(data2, cb2);
setTimeout(() => {
console.log('cb2.mock.calls[0][0]', cb2.mock.calls[0][0])
expect(cb2.mock.calls[0][0].error).toBeDefined();
done()
}, 1000)
Expand Down Expand Up @@ -1042,7 +1192,6 @@ describe('test file Upload method', () => {
fileUploadCb(fileData, cb2)

setTimeout(() => {
console.log('cb2.mock.calls', cb2.mock.calls);
expect(cb2.mock.calls[0][0].error).toBeDefined()
done()
}, 3000)
Expand All @@ -1059,7 +1208,6 @@ describe('test file Upload method', () => {
fileUploadCb(fileData, cb3)

setTimeout(() => {
console.log('cb3.mock.calls', cb3.mock.calls);
expect(cb3.mock.calls[0][0].error).toBeDefined()
done()
}, 1000)
Expand Down

0 comments on commit b9169bd

Please sign in to comment.