Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SK-1439 fix multiple unique column_names in get record request. #140

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vault-api/core/Reveal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}&`;
nikunj-skyflow marked this conversation as resolved.
Show resolved Hide resolved
});
} 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}&`;
});
}

Expand Down
83 changes: 83 additions & 0 deletions test/vault-api/Skyflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ const getByIdWithValidUniqColumnOptions= {
],
};

const getByIdWithValidMultipleUniqColumnOptions= {
records: [
{
table: "cards",
columnName: "abc",
columnValues: ["value","value2","value3"],
redaction: "PLAIN_TEXT",
},
],
};

const getByIdRes = {
records: [
{
Expand Down Expand Up @@ -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) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between the two tests? Somehow did not spot the different.


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: '<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: '<VaultID>',
vaultURL: 'https://www.vaulturl.com',
getBearerToken: () => {
return new Promise((resolve, _) => {
resolve("token")
})
}
});

const response = skyflow.get(getByIdWithValidMultipleUniqColumnOptions,{encodeURI:false});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roshmik {encode: false} is the option we have added in this test and not was in the above test.
My bad, didn't add it in description.

response.then((res) => {
expect((reqArg.url).match(/column_name=abc/gi)?.length).toBe(1);
done();
}).catch((er) => {
done(er)
});


});


Expand Down
Loading