strapi/api-tests/core/strapi/document-service/find-first.test.api.ts
Marc Roig d4d47227a6
feat: Initialize Document Service (#18558)
Co-authored-by: Ben Irvin <ben@innerdvations.com>
2023-11-28 12:01:27 +01:00

63 lines
1.7 KiB
TypeScript

import { LoadedStrapi } from '@strapi/types';
import { createTestSetup, destroyTestSetup } from '../../../utils/builder-helper';
import resources from './resources/index';
import { ARTICLE_UID, findArticleDb } from './utils';
describe('Document Service', () => {
let testUtils;
let strapi: LoadedStrapi;
beforeAll(async () => {
testUtils = await createTestSetup(resources);
strapi = testUtils.strapi;
});
afterAll(async () => {
await destroyTestSetup(testUtils);
});
describe('FindFirst', () => {
it('find first document with defaults', async () => {
const articleDb = await findArticleDb({ title: 'Article1-Draft-EN' });
const article = await strapi.documents(ARTICLE_UID).findFirst({});
expect(article).not.toBeNull();
expect(article).toMatchObject(articleDb);
});
it('find first document in french', async () => {
const articleDb = await findArticleDb({ title: 'Article1-Draft-FR' });
const article = await strapi.documents(ARTICLE_UID).findFirst({
locale: 'fr',
filters: {
title: { $startsWith: 'Article1' },
},
});
expect(article).toMatchObject(articleDb);
});
it('find one published document', async () => {
const article = await strapi.documents(ARTICLE_UID).findFirst({
status: 'published',
});
expect(article).toMatchObject({
publishedAt: expect.any(String),
});
});
it('find first draft document', async () => {
const article = await strapi.documents(ARTICLE_UID).findFirst({
status: 'draft',
});
expect(article).toMatchObject({
publishedAt: null,
});
});
});
});