From 9233049ff3ea46daddd9427e6d9556f2382b4144 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Thu, 12 Sep 2019 16:57:05 +0200 Subject: [PATCH] Show a helpful message only if test fails Inspired by the `ON FAIL` markup from the previous commit 0f2398295bcced3af3772bb4add1f42472c97893 --- .../src/middleware/slugifyMiddleware.spec.js | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/backend/src/middleware/slugifyMiddleware.spec.js b/backend/src/middleware/slugifyMiddleware.spec.js index 2a78e7975..6c8495e05 100644 --- a/backend/src/middleware/slugifyMiddleware.spec.js +++ b/backend/src/middleware/slugifyMiddleware.spec.js @@ -114,7 +114,7 @@ describe('slugifyMiddleware', () => { }) describe('but if the client specifies a slug', () => { - it('rejects CreatePost (on FAIL Neo4j constraints may not defined in database)', async () => { + it('rejects CreatePost', async (done) => { variables = { ...variables, title: 'Pre-existing post', @@ -122,18 +122,31 @@ describe('slugifyMiddleware', () => { slug: 'pre-existing-post', categoryIds, } - await expect( - mutate({ - mutation: createPostMutation, - variables, - }), - ).resolves.toMatchObject({ - errors: [ - { - message: 'Post with this slug already exists!', - }, - ], - }) + try { + await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({ + errors: [ + { + message: 'Post with this slug already exists!', + }, + ], + }) + done() + } catch(error) { + throw new Error(` + ${error} + + Probably your database has no unique constraints! + + To see all constraints go to http://localhost:7474/browser/ and + paste the following: + \`\`\` + CALL db.constraints(); + \`\`\` + + Learn how to setup the database here: + https://docs.human-connection.org/human-connection/neo4j + `) + } }) }) })