diff --git a/__test__/metadata/Product/findProduct.test.ts b/__test__/metadata/Product/findProduct.test.ts index c5dd419a..305ed256 100644 --- a/__test__/metadata/Product/findProduct.test.ts +++ b/__test__/metadata/Product/findProduct.test.ts @@ -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}`, @@ -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; + }); }); }); diff --git a/src/imports/data/data.js b/src/imports/data/data.js index 63605fe4..a88af7bd 100644 --- a/src/imports/data/data.js +++ b/src/imports/data/data.js @@ -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; }, {}), );