chore: rectifies test issues

This commit is contained in:
James
2023-09-15 17:12:13 -04:00
parent 92b4490257
commit 5292f41a3b
5 changed files with 100 additions and 28 deletions

View File

@@ -22,6 +22,15 @@ describe('collections-rest', () => {
beforeAll(async () => {
const { serverURL } = await initPayloadTest({ __dirname, init: { local: false } })
client = new RESTClient(await config, { serverURL, defaultSlug: slug })
// Wait for indexes to be created,
// as we need them to query by point
await new Promise((resolve, reject) => {
payload.db.collections[pointSlug].ensureIndexes(function (err) {
if (err) reject(err)
resolve(true)
})
})
})
afterAll(async () => {
@@ -245,7 +254,7 @@ describe('collections-rest', () => {
const { status, docs } = await client.deleteMany<Post>({
where: { title: { equals: 'title' } },
});
})
expect(status).toEqual(200)
expect(docs[0].title).toEqual('title') // Check was not modified
@@ -306,17 +315,29 @@ describe('collections-rest', () => {
})
it('should query - equals', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: 'custom-id-name' } });
const { result } = await client.find({ slug: customIdSlug, query: { id: { equals: customId } } });
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`
const { doc } = await client.create({
slug: customIdSlug,
data: { id: customId, name: 'custom-id-name' },
})
const { result } = await client.find({
slug: customIdSlug,
query: { id: { equals: customId } },
})
expect(result.docs.map(({ id }) => id)).toContain(doc.id);
});
expect(result.docs.map(({ id }) => id)).toContain(doc.id)
})
it('should query - like', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: 'custom-id-name' } });
const { result } = await client.find({ slug: customIdSlug, query: { id: { like: 'custom' } } });
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`
const { doc } = await client.create({
slug: customIdSlug,
data: { id: customId, name: 'custom-id-name' },
})
const { result } = await client.find({
slug: customIdSlug,
query: { id: { like: 'custom' } },
})
expect(result.docs.map(({ id }) => id)).toContain(doc.id)
})