I’m trying to run this test on sqlite, but seems like I’m unable to persist data after using the entityService:
import request from 'supertest'
import {
setPublicPermissions,
updatePluginStore,
setupStrapi,
stopStrapi,
sleep
} from './../helpers/strapi'
import { describe, beforeAll, afterAll, it, expect, test } from '@jest/globals'
/** this code is called once before any test is called */
beforeAll(async () => {
await setupStrapi()
})
/** this code is called once before all the tested are finished */
afterAll(async () => {
await stopStrapi()
})
describe("Library's tests", () => {
beforeAll(async () => {
await setPublicPermissions({
library: ['find', 'findOne']
})
})
it('should return an empty list of libraries', async () => {
await request(strapi.server.httpServer)
.get('/api/libraries')
.expect(200)
.then(res => {
expect(res.body.data).toStrictEqual([])
})
})
it('should return a list of libraries', async () => {
const createdLibrary = await strapi.entityService.create(
'api::library.library',
{
data: {
title: 'My first library',
copies: 1
}
}
)
console.log(createdLibrary)
expect(createdLibrary.title).toBe('My first library')
await request(strapi.server.httpServer)
.get('/api/libraries')
.expect(200)
.then(res => {
expect(res.body).toBeDefined()
expect(res.body.data.length).toBe(1)
expect(res.body.data).toStrictEqual([])
})
})
})