Browse Source

refactor(friend-support): improve single test clarity

Rename test functions to explicit what is being tested
DEV-4017-prototypes-exercise-1-animals
nprimo 2 years ago committed by Niccolò Primo
parent
commit
de95b3b572
  1. 22
      js/tests/friend-support_test.mjs

22
js/tests/friend-support_test.mjs

@ -51,14 +51,13 @@ export const setup = async ({ randStr }) => {
return { tmpPath: dir, createFilesIn, randLastName, sendRequest, startServer } return { tmpPath: dir, createFilesIn, randLastName, sendRequest, startServer }
} }
tests.push(async ({ path, ctx }) => { const isServerRunningWell = async ({ path, ctx }) => {
const { server, message } = await ctx.startServer(path) const { server, message } = await ctx.startServer(path)
server.kill() server.kill()
return message[0].toString().includes(port) return message[0].toString().includes(port)
}) }
tests.push(async ({ path, eq, ctx, randStr }) => { const testOneGuest = async ({ path, eq, ctx, randStr }) => {
// test for one guest
const { server } = await ctx.startServer(path) const { server } = await ctx.startServer(path)
const randMsg = randStr() const randMsg = randStr()
const expBody = { message: randMsg } const expBody = { message: randMsg }
@ -85,11 +84,9 @@ tests.push(async ({ path, eq, ctx, randStr }) => {
contentType: 'application/json', contentType: 'application/json',
}, },
) )
}) }
tests.push(async ({ path, eq, ctx }) => { const testServerFail = async ({ path, eq, ctx }) => {
// test server failed
// change permission for existing file
const { server } = await ctx.startServer(path) const { server } = await ctx.startServer(path)
await chmod(`${ctx.tmpPath}/guests/mario_${ctx.randLastName}.json`, 0) await chmod(`${ctx.tmpPath}/guests/mario_${ctx.randLastName}.json`, 0)
const { status, body, headers } = await ctx.sendRequest( const { status, body, headers } = await ctx.sendRequest(
@ -111,10 +108,9 @@ tests.push(async ({ path, eq, ctx }) => {
contentType: 'application/json', contentType: 'application/json',
}, },
) )
}) }
tests.push(async ({ path, eq, ctx }) => { const testGuestNotThere = async ({ path, eq, ctx }) => {
// test guest not there
const { server } = await ctx.startServer(path) const { server } = await ctx.startServer(path)
const { status, body, headers } = await ctx.sendRequest('/andrea_bianchi', { const { status, body, headers } = await ctx.sendRequest('/andrea_bianchi', {
method: 'GET', method: 'GET',
@ -132,6 +128,8 @@ tests.push(async ({ path, eq, ctx }) => {
contentType: 'application/json', contentType: 'application/json',
}, },
) )
}) }
tests.push(isServerRunningWell, testOneGuest, testServerFail, testGuestNotThere)
Object.freeze(tests) Object.freeze(tests)

Loading…
Cancel
Save