diff --git a/src/vault-api/core/Reveal.ts b/src/vault-api/core/Reveal.ts index 6f34f24..582026d 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..fdb5122 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,78 @@ 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) + }); + + + }); + + 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) + }); + + });