mirror of
https://github.com/strapi/strapi.git
synced 2025-10-05 13:23:55 +00:00
63 lines
1.7 KiB
TypeScript
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,
|
|
});
|
|
});
|
|
});
|
|
});
|