From 90517e27d2cb0c85c2bc79e945b1f516729ac3a5 Mon Sep 17 00:00:00 2001 From: yaswanth-pula-skyflow Date: Thu, 25 Jan 2024 08:39:21 +0530 Subject: [PATCH 1/3] SK-1439 fix multiple unique column_name in get record request. --- src/vault-api/core/Reveal.ts | 8 +++--- test/vault-api/Skyflow.test.js | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/vault-api/core/Reveal.ts b/src/vault-api/core/Reveal.ts index 6f34f24..7e443e7 100644 --- a/src/vault-api/core/Reveal.ts +++ b/src/vault-api/core/Reveal.ts @@ -66,13 +66,13 @@ const getSkyflowIdRecordsFromVault = ( }); if (options && Object.prototype.hasOwnProperty.call(options, 'encodeURI') && options?.encodeURI === false){ - skyflowIdRecord.columnValues?.forEach((column) => { - paramList += `column_name=${skyflowIdRecord.columnName}&column_values=${column}&`; + skyflowIdRecord.columnValues?.forEach((column,index) => { + paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}`:''}&column_values=${column}&`; }); } else { - skyflowIdRecord.columnValues?.forEach((column) => { + skyflowIdRecord.columnValues?.forEach((column,index) => { var encode_column_value = encodeURIComponent(column) - paramList += `column_name=${skyflowIdRecord.columnName}&column_values=${encode_column_value}&`; + paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}`:''}&column_values=${encode_column_value}&`; }); } diff --git a/test/vault-api/Skyflow.test.js b/test/vault-api/Skyflow.test.js index 31dbc24..3d4348d 100644 --- a/test/vault-api/Skyflow.test.js +++ b/test/vault-api/Skyflow.test.js @@ -751,6 +751,17 @@ const getByIdWithValidUniqColumnOptions= { ], }; +const getByIdWithValidMultipleUniqColumnOptions= { + records: [ + { + table: "cards", + columnName: "abc", + columnValues: ["value","value2","value3"], + redaction: "PLAIN_TEXT", + }, + ], +}; + const getByIdRes = { records: [ { @@ -1930,6 +1941,42 @@ describe('get method with options', () => { }); + }); + + test('get method should send request url with single column name for multiple column value', (done) => { + + let reqArg; + const clientReq = jest.fn((arg) => { + reqArg = arg; + return Promise.resolve({data:getByIdRes}) + }); + + const mockClient = { + config: skyflowConfig, + request: clientReq, + metadata: {} + } + + clientModule.mockImplementation(() => { return mockClient }); + skyflow = Skyflow.init({ + vaultID: '', + vaultURL: 'https://www.vaulturl.com', + getBearerToken: () => { + return new Promise((resolve, _) => { + resolve("token") + }) + } + }); + + const response = skyflow.get(getByIdWithValidMultipleUniqColumnOptions); + response.then((res) => { + expect((reqArg.url).match(/column_name=abc/gi)?.length).toBe(1); + done(); + }).catch((er) => { + done(er) + }); + + }); From efba311a9de059452ba0ede1db55c722ac20e077 Mon Sep 17 00:00:00 2001 From: yaswanth-pula-skyflow Date: Thu, 25 Jan 2024 09:04:44 +0530 Subject: [PATCH 2/3] SK-1439 update unique column_name test case. --- test/vault-api/Skyflow.test.js | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/vault-api/Skyflow.test.js b/test/vault-api/Skyflow.test.js index 3d4348d..fdb5122 100644 --- a/test/vault-api/Skyflow.test.js +++ b/test/vault-api/Skyflow.test.js @@ -1977,6 +1977,42 @@ describe('get method with options', () => { }); + }); + + test('get method should send request url with single column name for multiple column value', (done) => { + + let reqArg; + const clientReq = jest.fn((arg) => { + reqArg = arg; + return Promise.resolve({data:getByIdRes}) + }); + + const mockClient = { + config: skyflowConfig, + request: clientReq, + metadata: {} + } + + clientModule.mockImplementation(() => { return mockClient }); + skyflow = Skyflow.init({ + vaultID: '', + vaultURL: 'https://www.vaulturl.com', + getBearerToken: () => { + return new Promise((resolve, _) => { + resolve("token") + }) + } + }); + + const response = skyflow.get(getByIdWithValidMultipleUniqColumnOptions,{encodeURI:false}); + response.then((res) => { + expect((reqArg.url).match(/column_name=abc/gi)?.length).toBe(1); + done(); + }).catch((er) => { + done(er) + }); + + }); From f090c462c31dc8a2d7b704f44796d4964191a738 Mon Sep 17 00:00:00 2001 From: yaswanth-pula-skyflow Date: Thu, 25 Jan 2024 09:32:40 +0530 Subject: [PATCH 3/3] SK-1439 update the unique column name appending the request url --- src/vault-api/core/Reveal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vault-api/core/Reveal.ts b/src/vault-api/core/Reveal.ts index 7e443e7..582026d 100644 --- a/src/vault-api/core/Reveal.ts +++ b/src/vault-api/core/Reveal.ts @@ -67,12 +67,12 @@ const getSkyflowIdRecordsFromVault = ( if (options && Object.prototype.hasOwnProperty.call(options, 'encodeURI') && options?.encodeURI === false){ skyflowIdRecord.columnValues?.forEach((column,index) => { - paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}`:''}&column_values=${column}&`; + paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}&`:''}column_values=${column}&`; }); } else { skyflowIdRecord.columnValues?.forEach((column,index) => { var encode_column_value = encodeURIComponent(column) - paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}`:''}&column_values=${encode_column_value}&`; + paramList += `${index === 0 ?`column_name=${skyflowIdRecord.columnName}&`:''}column_values=${encode_column_value}&`; }); }