Commit Graph

28 Commits

Author SHA1 Message Date
Naz
f48892028d Fixed failing snapshot match in members
no issue

- The test was failing because the match for a the data has changed, which was returned in a short format YYYY-MM-DD.
- Added a new matcher for short date format -anyShortDate. Can be used for match dynamic dates in short format
2022-02-18 11:30:14 +07:00
Naz
884f837bd7 Improved webhooks e2e test bootstrap speed
refs https://github.com/TryGhost/Toolbox/issues/214

- Calling `getMembersAPIAgent` and `getAdminAPIAgent` separately was booting Ghost twice, which caused a significant performance degradation.
- Additionally, having two calls was slightly ugly and having once utility function that delivers multiple agents at once feels like  more readable syntax
2022-02-17 15:31:57 +07:00
Hannah Wolfe
6a2755893e
Added new matcher for location strings
- Often in our API we want to check that the location string looks roughly right for a resource
- At the moment we're matching any String, this upgrades the check to look for resource URLs
2022-02-16 13:48:56 +00:00
Hannah Wolfe
0ab2f36c22
Added settingsCache handling to e2e-framework
refs: https://github.com/Ghost/Ghost/commit/b5ee17b25

- When moving the site tests into e2e-api they broke because they were getting the changed settings value from the settings test
- The solution is to ensure the settingsCache is reset between tests, which is what this commit does
- This commit also renames the shutdown method to reset, because this is not a permanent operation
- It also renames the resetDb method to resetData, because the concept is we want the internal data to be reset, not just the DB
2022-02-11 16:24:24 +00:00
Fabien "egg" O'Carroll
126fc8cb81 Fixed e2e-framework not waiting for Ghost to start
no-issue

Because we were returning the call to `boot`, rather than awaiting it,
it meant that once a test was provided with an API Agent the Ghost
application hadn't necessarily started. This was noticed whilst working
on the Members API which requires the frontend to be loaded.

When the frontend is loaded we must also wait for the url service to
have finished initialising, so that we do not run into 503 maintenance
errors when hitting the frontend.
2022-02-11 15:56:09 +02:00
Fabien "egg" O'Carroll
af66ab02c8 Added getMembersAPIAgent to e2e-framework
no-issue

The Members API is served on a different endpoint to the Admin API, and
also requires that the frontend is booted. This agent is to be used when
testing the Members API, e.g. Stripe webhooks or Members config.
2022-02-11 15:56:09 +02:00
Hannah Wolfe
e30498ca2c
Enabled jsdoc in tests + fixed issue in e2e framework
- Enabled jsdoc type checking in tests
- Fixed a minor issue I just committed to the e2e framework
2022-02-11 12:48:02 +00:00
Hannah Wolfe
00e4a8cad4
Add option to include member in the adminAPIAgent
- The admin API test agent doesn't boot the Ghost frontend, which is where members routes are currently located
- This means we can't test members properly as we don't have access to webhooks etc
- This change adds a members option to getAdminAPIAgent(), which in turn enables the frontend
- We do it this way so that we can easily change the implementation later, e.g. if we have the option to boot members directly
2022-02-11 12:37:00 +00:00
Hannah Wolfe
9375a1701a
Revert "Fixed theme storage getting confused between tests"
This reverts commit 3e7039c47d.
2022-02-11 11:09:21 +00:00
Hannah Wolfe
3e7039c47d
Fixed theme storage getting confused between tests
- When starting ghost for e2e tests we create a content folder in the os tmp dir
- This means that the folder can change between suites as ghost is started and restarted
- For the most part this is fine, but theme storage caches the path to config (which makes sense, it's not meant to change whilst Ghost is in-memory)
- This is a quick-n-dirty fix that just makes it possible to update that path in the tests, so we know it's in sync
- Ideally we'd not cache the path, use a function to fetch it etc, or fully reset the theme storage layer, but this is the fix I have working today
     and so it's going in to unblock things for now
2022-02-11 10:37:37 +00:00
Hannah Wolfe
dabf143cae
Fixed Ghost boot errors being masked
- This was a total derp on my side, wanted to change the error message, not remove the error
2022-02-11 10:21:45 +00:00
Hannah Wolfe
83aa35241a
Added mockLabsDisabled to e2e framework
- Can now easily mock labs flags as enabled or disabled using mockManager
- Updated some bits of code that directly mocked labs
- Aside: improved error thrown when things go wrong booting Ghost
2022-02-10 12:10:31 +00:00
Hannah Wolfe
527cb01680 Updated members tests to use snapshot testing
refs: https://github.com/TryGhost/Toolbox/issues/158

- This is a reference suite - it shows how snapshot testing can be used on a larger suite
2022-02-09 20:15:58 +00:00
Hannah Wolfe
ac85208441
Cleaned up reference tests
refs: https://github.com/TryGhost/Toolbox/issues/158

- continuing to turn this into a reference test suite for how to do things with the new framework
- use fixtureManager and mockManager properly
- testUtils should _not_ be required anymore!
- TODO: cleanup labs mocking and side effect assertion using models
2022-02-08 20:12:10 +00:00
Hannah Wolfe
2c14923bb6
Renamed mock-utils to mock-manager
refs: https://github.com/TryGhost/Toolbox/issues/158

- continuing to try to make the framework as clean as possible
2022-02-08 20:12:09 +00:00
Hannah Wolfe
414344c86c
Improved property matchers concept in e2e-framework
refs: https://github.com/TryGhost/Toolbox/issues/158

- rather than just exposing any, anything and string matching, expose more specific matchers.
- this was triggered by `any(Date)` not working for dates in our API
- it seems poor to match `any(String)` for something we want to be a well formatted date
- establishes the pattern of using our defined matchers instead of requiring any/anything from jest
2022-02-08 16:36:08 +00:00
Hannah Wolfe
d7c2759b3f
Improved agentProvider api in e2e-framework
refs: https://github.com/TryGhost/Toolbox/issues/158

- Working up to having these be the defacto "reference" tests
- Changing this allows for the fact that there will be a getContentAPIAgent, and probably more in future
- Abstracting away the path to a single location will make updating API paths easier later too
2022-02-08 14:39:24 +00:00
Hannah Wolfe
069c344495
Switched new e2e-framework to use our own snapshot lib (#14137)
refs TryGhost/Toolbox#158
refs TryGhost/Toolbox#129 (comment)

We now have @tryghost/jest-snapshot - a suite of utilities for using snapshots with mocha, should, etc
The @tryghost/express-test lib also uses it to provide chained snapshot assertions

This library was created because all the existing implementations I could find, including the in use @ethanresnick/chai-jest-snapshot
didn't properly support property matching. @ethanresnick/chai-jest-snapshot supposedly supported it, but the implementation was incorrect
and frequently lead to false test passes.

This library also has (after some back and forth) path resolution so that snapshots can live in a local __snapshots__ folder
2022-02-08 14:33:19 +00:00
Hannah Wolfe
5210e84b26
Improved e2e-framework API
- encapsulated concerns within individual objects
- this will allow us to refactor these into classes or move them around later
- also makes it clearer how methods like restore relate to other methods
- e.g mocks.restore() restores mocks, whilst fixtureManager.restore() restores the database
2022-02-07 16:09:54 +00:00
Hannah Wolfe
82d2228bca
Added db reset to new e2e framework
- Ensure that the DB is always reset between tests
- We assume that the DB will be torn down and rebuilt between tests
- Without this, previous tests clobber the current tests, and it's not possible to tell when running files in isolation
which makes developing really tricky
2022-02-07 16:09:54 +00:00
Hannah Wolfe
c9ca388a9f
Added new express-test framework to our ref tests (#14117) 2022-02-06 16:18:12 +00:00
Naz
868ae96100 Removed copy-pasta code form TestAgent
refs https://github.com/TryGhost/Toolbox/issues/158

- To make the development quicker the copy-paste code was left in the codebase but gave immediate smell. Removed it to stop bothering me every time I look at the related code :)
2021-12-13 13:13:17 +04:00
Naz
f4ad3b23ba Removed need for 'Origin' header in test suites
refs https://github.com/TryGhost/Toolbox/issues/129

- The "Origin" header is require in Admin API requests so it makes sense to bake it into a default request made by most tests. Reduces unnecesary fluf around test request setup and removes a "config" dependency in each tests suite using the "e2e framework"
2021-12-10 11:05:37 +04:00
Naz
ea872101a0 Fixed linting error
refs 309e14b8c9
2021-12-09 15:18:15 +04:00
Naz
309e14b8c9 Moved email stubbing logic into e2e-framework utils
refs https://github.com/TryGhost/Toolbox/issues/158

- Moving common mocking/stubbing/spying logic into an outside utils module allows test suites to keep agnostic towards which framework powers mocking etc. Should also substitute email service stubbing used in multiple places
- Bonus, got rid of should dependency, which is deprecated
2021-12-09 15:10:13 +04:00
Naz
eb35c64f19 Added content folder initialization to e2e-framework
refs https://github.com/TryGhost/Toolbox/issues/129

- Adds content folder creation based on fixtures for e2e tests using the e2e framework
- Mostly a copy-paste for now from existing e2e utils with some simplifications, so we can "complicate things" later only if needed
2021-12-09 22:20:54 +13:00
Naz
2ae0d8ef32 Added e2e framework
refs 24505db918

- The code is heavily borrowed from the referenced commit by @ErisDS. It starts a fresh abstraction layer for all e2e tests to use, provides simle interface for request agent initialization and state management (read the e2e-framework top file description for more)
- Main methods the framework exposes are:
  - getAgent - to initialize request agent with a fresh Ghost instance
  - initFixtures - to initializer a fresh db state
  - resetDb - cleans up the db state if there were state manipulations during the test suite run (POST, PUT requests or non-default fixtures)
2021-12-09 22:20:54 +13:00
Naz
6762e2a60d Started a greenfield e2e test framework
refs https://github.com/TryGhost/Toolbox/issues/129

- Having a fresh module should allow building new testing utility concepts from the ground up without being tied by the mystery baggage of the legacy localUtils/testUtils
- The outline of the concepts the framework will be handling is in the commont on the top of the e2e-framework file
2021-12-09 22:20:54 +13:00