From 320c6e0dd3f9338081f7284d7a800c3c39d412f4 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 5 Oct 2022 17:22:08 +0800 Subject: [PATCH] Abstracted a hacky local URL matcher refs https://github.com/TryGhost/Toolbox/issues/320 - The URL matcher is very likely to be reused in the future, so having it abstracted away gives two benefits: 1. Central place to document hacky behavior and easier future cleanup 2. The implementer of the e2e test does not have to see the "hacky note" and just concentrate on the implementation of the test --- ghost/core/test/e2e-webhooks/posts.test.js | 6 ++---- ghost/core/test/utils/e2e-framework.js | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ghost/core/test/e2e-webhooks/posts.test.js b/ghost/core/test/e2e-webhooks/posts.test.js index ad9f435843..2932c4cef2 100644 --- a/ghost/core/test/e2e-webhooks/posts.test.js +++ b/ghost/core/test/e2e-webhooks/posts.test.js @@ -1,5 +1,5 @@ const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework'); -const {anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber, stringMatching} = matchers; +const {anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber, anyLocalURL} = matchers; const tierSnapshot = { id: anyObjectId, @@ -35,9 +35,7 @@ const buildPostSnapshotWithTiers = ({published, tiersCount, roles = false}) => { published_at: published ? anyISODateTime : null, created_at: anyISODateTime, updated_at: anyISODateTime, - // @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341 - // this matcher should be removed once the issue is solved - url: stringMatching(/http:\/\/127.0.0.1:2369\/\w+\//), + url: anyLocalURL, tiers: new Array(tiersCount).fill(tierSnapshot), primary_author: buildAuthorSnapshot(roles), authors: new Array(1).fill(buildAuthorSnapshot(roles)) diff --git a/ghost/core/test/utils/e2e-framework.js b/ghost/core/test/utils/e2e-framework.js index 222e272bec..68b0754909 100644 --- a/ghost/core/test/utils/e2e-framework.js +++ b/ghost/core/test/utils/e2e-framework.js @@ -368,6 +368,10 @@ module.exports = { anyLocationFor: (resource) => { return stringMatching(new RegExp(`https?://.*?/${resource}/[a-f0-9]{24}/`)); }, + // @NOTE: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341 + // this matcher should be removed once the issue is solved - routing is redesigned + // An ideal solution would be removal of this matcher altogether. + anyLocalURL: stringMatching(/http:\/\/127.0.0.1:2369\/\w+\//), stringMatching },