test: improve expects

This commit is contained in:
Dan Ribbens
2023-09-13 13:04:06 -04:00
parent bb16ce965c
commit 33e50f7d6b
2 changed files with 13 additions and 4 deletions

View File

@@ -173,8 +173,9 @@ describe('collections-graphql', () => {
const response = await client.request(query);
const { docs } = response.Posts;
const docsWithWhereTitleNotEqualPostTitle = docs.filter((post) => post.title === post1.title);
expect(docs[0]).toMatchObject({ id: post2.id, title: post2.title });
expect(docsWithWhereTitleNotEqualPostTitle).toHaveLength(0);
});
it('like', async () => {
@@ -261,14 +262,14 @@ describe('collections-graphql', () => {
docs {
id
title
number
}
}
}`;
const response = await client.request(query);
const { docs } = response.Posts;
expect(docs).toContainEqual(expect.objectContaining({ id: numPost2.id }));
expect(docs.map(({ id }) => id)).toContain(numPost2.id);
});
it('greater_than_equal', async () => {

View File

@@ -289,7 +289,15 @@ describe('collections-rest', () => {
expect(foundDoc.id).toEqual(doc.id);
});
it('should query', async () => {
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 } } });
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' } } });