Skip to content

Commit 87035c1

Browse files
committed
Add tests for attributesToRetrieve in getDocuments
1 parent a6c0020 commit 87035c1

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/documents_tests.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,41 @@ describe.each([
6767
})
6868
await client.getIndex(uidAndPrimaryKey.uid).waitForPendingUpdate(updateId)
6969
})
70+
test(`${permission} key: Get documents with string attributesToRetrieve`, async () => {
71+
await client
72+
.getIndex(uidNoPrimaryKey.uid)
73+
.getDocuments({
74+
attributesToRetrieve: 'id',
75+
})
76+
.then((response) => {
77+
expect(response.find((x) => Object.keys(x).length !== 1)).toEqual(
78+
undefined
79+
)
80+
})
81+
})
82+
83+
test(`${permission} key: Get documents with array attributesToRetrieve`, async () => {
84+
await client
85+
.getIndex(uidNoPrimaryKey.uid)
86+
.getDocuments({
87+
attributesToRetrieve: ['id'],
88+
})
89+
.then((response) => {
90+
expect(response.find((x) => Object.keys(x).length !== 1)).toEqual(
91+
undefined
92+
)
93+
})
94+
})
95+
7096
test(`${permission} key: Get documents from index that has no primary key`, async () => {
7197
await client
7298
.getIndex(uidNoPrimaryKey.uid)
73-
.getDocuments()
99+
.getDocuments({
100+
attributesToRetrieve: 'id',
101+
})
74102
.then((response) => {
103+
console.log({ response })
104+
75105
expect(response.length).toEqual(dataset.length)
76106
})
77107
})
@@ -83,6 +113,7 @@ describe.each([
83113
expect(response.length).toEqual(dataset.length)
84114
})
85115
})
116+
86117
test(`${permission} key: Replace documents from index that has NO primary key`, async () => {
87118
const id = 2
88119
const title = 'The Red And The Black'

0 commit comments

Comments
 (0)