Skip to content

Commit

Permalink
fix: find with field projection
Browse files Browse the repository at this point in the history
  • Loading branch information
CaduGomes committed Nov 13, 2023
1 parent f79bd50 commit d72976b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 22 additions & 1 deletion __test__/metadata/Product/findProduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Find Product', () => {
// Arrange

// Act
const data = (await fetch(`http://127.0.0.1:3000/rest/data/Product/find?fields=name,status,code`, {
const data = (await fetch(`http://127.0.0.1:3000/rest/data/Product/find`, {
method: 'GET',
headers: {
Cookie: `_authTokenId=${authId}`,
Expand All @@ -51,5 +51,26 @@ describe('Find Product', () => {
expect(data.data?.[0].status).to.be.equal('draft');
expect(data.data?.[0].code).to.be.equal(1);
});

it('Find Product with field projection', async () => {
// Arrange

// Act
const data = (await fetch(`http://127.0.0.1:3000/rest/data/Product/find?fields=name`, {
method: 'GET',
headers: {
Cookie: `_authTokenId=${authId}`,
'Content-Type': 'application/json',
},
}).then(res => res.json())) as KonectyResponse;

// Assert
expect(data.success).to.be.equal(true);
expect(data.data?.length).to.be.equal(1);
// compare data.data with the data created in beforeEach
expect(data.data?.[0].name).to.be.equal('Teste');
expect(data.data?.[0].status).to.be.undefined;
expect(data.data?.[0].code).to.be.undefined;
});
});
});
5 changes: 0 additions & 5 deletions src/imports/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ export async function find({ authTokenId, document, displayName, displayType, fi
acc[key] = record[key];
}

// Remove the fields only used for conditions comparison
if (fieldsObject[key] === 0 || (emptyFields && key in fieldsObject === false)) {
delete acc[key];
}

return acc;
}, {}),
);
Expand Down

0 comments on commit d72976b

Please sign in to comment.