()
| 179 | } |
| 180 | |
| 181 | export function setupServer(): void { |
| 182 | let fastify: FastifyTestInstance; |
| 183 | beforeAll(async () => { |
| 184 | if (process.env.FCC_ENABLE_TEST_LOGGING !== 'true') { |
| 185 | delete buildOptions.loggerInstance; |
| 186 | } |
| 187 | fastify = await build(buildOptions); |
| 188 | await fastify.ready(); |
| 189 | |
| 190 | await checkCanConnectToDb(fastify.prisma); |
| 191 | |
| 192 | // Prisma does not support TTL indexes in the schema yet, so, to avoid |
| 193 | // conflicts with the TTL index in the sessions collection, we need to |
| 194 | // create it manually (before interacting with the db in any way). Also, |
| 195 | // to save time, we create all other indexes so we don't need to invoke |
| 196 | // `prisma db push` (which is relatively slow). |
| 197 | |
| 198 | await Promise.all( |
| 199 | indexData.map(async ({ collection, indexes }) => { |
| 200 | await fastify.prisma.$runCommandRaw({ |
| 201 | createIndexes: collection, |
| 202 | indexes |
| 203 | }); |
| 204 | }) |
| 205 | ); |
| 206 | |
| 207 | global.fastifyTestInstance = fastify; |
| 208 | // allow a little time to setup the db |
| 209 | }, 10000); |
| 210 | |
| 211 | afterAll(async () => { |
| 212 | if (!global.fastifyTestInstance) |
| 213 | throw Error(`fastifyTestInstance was not created. Typically this means that something went wrong when building the fastify instance. |
| 214 | If you are seeing this error, the root cause is likely an error thrown in the beforeAll hook.`); |
| 215 | await fastifyTestInstance.prisma.$runCommandRaw({ dropDatabase: 1 }); |
| 216 | |
| 217 | await fastifyTestInstance.close(); |
| 218 | }); |
| 219 | } |
| 220 | |
| 221 | // demoUser _id to allow testing with mock data |
| 222 | export const defaultUserId = '5bd30e0f1caf6ac3ddddddb5'; |
nothing calls this directly
no test coverage detected