Commit Graph

15499 Commits

Author SHA1 Message Date
Fabien 'egg' O'Carroll
daa39bf4fe
🐛 Fixed error handling webhooks for unknown member (#14155)
https://github.com/TryGhost/Team/issues/1374

When we receive a web hook to update payment details for a customer
which is not associated with a Member, instead of proceeding and erroring
we now return early and respond to Stripe with a 200. A test has been 
added to ensure this
2022-02-17 14:51:40 +02:00
Renovate Bot
d2081059de Update dependency @playwright/test to v1.19.1 2022-02-17 12:32:55 +01:00
Daniel Lockyer
33d4a711e0
Fixed inputs being passed as env variables in CI
- turns out we need `github.event` prepended to the variable for it to
  work
2022-02-17 12:25:30 +01:00
Daniel Lockyer
b1bb2ad8e8
Fixed syntax of inputs in CI workflow
- the inputs should be under an `inputs` key - not sure where that went
  missing
2022-02-17 12:20:29 +01:00
Daniel Lockyer
1a0362f3db Added demo E2E browser test
refs https://github.com/TryGhost/Toolbox/issues/207

- we want to start writing some E2E tests that involve automated
  pointing and clicking around the frontend of Ghost to test that
  members of Ghost sites can still do what we expect
- we've decided to look in to Playwright for this - it looks __really__
  nice
- this is a VERY basic first test - it'll check for a 200 on the
  homepage of whatever we provide as the TEST_URL env variable, or
  default to a (manually-run) Ghost instance on port 2368
- also adds a `yarn test:browser` command to run the tests using the
  Playwright CLI, and a sample GitHub Action workflow which we can
  manually run with a site URL
- there's a lot more to add here in terms of test framework but this
  gets us started
2022-02-17 12:16:58 +01: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
Renovate Bot
9b4d61ef2e
Update dependency express to v4.17.3 2022-02-17 04:02:30 +00:00
Naz
f0bda014ab Fixed misconfigured SnapshotManager in e2e tests
refs https://github.com/TryGhost/Toolbox/issues/210

- After updating to the newest `@tryghost/express-test`, it's dependency `@tryghost/jest-snapshot` was missmatched with the one used in Ghost itself. This caused multiple instances of SnapshotManager class in the system, which is meant to be a singleton!
- The issue was causing following error to appear: "IncorrectUsageError: Unable to run snapshot tests, current test was not configured"
2022-02-17 11:01:15 +07:00
Naz
d79dab94f5 Changed test-framework assertion execution order
refs https://github.com/TryGhost/Toolbox/issues/210

- Having assertions executed in the declaration order using superagent has lead to many frustrating developer experiences. For example when status code assertion fails there was usually no additional context to investigate the failure further. In this situation having a "response body" assertion executed usually would give many more clues on the actual problem at hand.
- The order of the assertions has been changed from the order in which they were declared to the following one based on assertion type:
1. `exect`
2. `expectHeader`
3. `expectStatus`

- For more on this topic check the documentation: cfd6e88fe2/packages/express-test (assertion-execution-order)
2022-02-17 11:01:15 +07:00
Daniel Lockyer
55204bf725 Fixed admin views path mocking override in tests
- for some reason, this test seems to be failing now we've pulled it out
  of the general CI
- it makes sense when the repo is clean, because the html files don't
  exist, but I don't understand how they were working before... 🤔
- anyway, we should be overriding the path to the test fixtures admin
  view files here
- this fixes the unit tests
2022-02-16 19:22:20 +01:00
Daniel Lockyer
08eaed152b Added yarn test:ci command
refs https://github.com/TryGhost/Toolbox/issues/208

- we currently run all test commands separately in CI and this can make
  it harder to replicate any issues we see in CI because we have to
  manually go and copy the order of the tests
- it's also nicer if there's just one command that runs so we can make
  changes globally to CI
- this commit adds a test:ci yarn command which will run the tests in
  order of speed/importance, with the -b AKA fail-fast flag so we
  don't have to wait for all tests to run before finding out about
  issues
- this also cleans up running unit tests in the DB matrix
2022-02-16 19:22:20 +01:00
Daniel Lockyer
7a5b262a84 Renamed CI test workflows
- these names are a little more descriptive and look better in GitHub
2022-02-16 19:22:20 +01:00
Daniel Lockyer
d4759d30a7 Split out unit tests from CI matrix
refs https://github.com/TryGhost/Toolbox/issues/208

- unit tests (shouldn't) be database dependent so they don't need to be
  included in the DB matrix
- this prevents an extra 6 executions of unit tests, which isn't a big
  deal given they only take 10s to run, but semantically they belong
  outside so this commit does that
- also updates the canary step to rely on this extra test run
2022-02-16 19:22:20 +01:00
Renovate Bot
6537ed1485
Update dependency @sentry/node to v6.17.9 2022-02-16 15:26:45 +00:00
Matt Hanley
4b47d376ec Merged v4.36.1 into main
v4.36.1
2022-02-16 15:25:03 +00:00
Daniel Lockyer
ffd66d5c57 v4.36.1 2022-02-16 15:23:42 +00:00
Daniel Lockyer
95371ee71a Updated Admin to v4.36.1 2022-02-16 15:23:42 +00:00
Kevin Ansfield
9debf27e62 🐛 Fixed "Invalid mobiledoc structure" errors the could occur when saving posts with header cards
refs https://github.com/TryGhost/Team/issues/1377

- bumped all packages that have a dependency on `@tryghost/kg-utils` to fix a bug in the `slugify()` utility that was throwing errors when the header or subheader was left blank in a header card
2022-02-16 15:16:10 +00:00
Kevin Ansfield
de644a25d4 🐛 Fixed "Invalid mobiledoc structure" errors the could occur when saving posts with header cards
refs https://github.com/TryGhost/Team/issues/1377

- bumped all packages that have a dependency on `@tryghost/kg-utils` to fix a bug in the `slugify()` utility that was throwing errors when the header or subheader was left blank in a header card
2022-02-16 14:44:33 +00: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
Thibaut Patel
bed0115ddd
Added an e2e test for creating a member subscription
refs https://github.com/TryGhost/Team/issues/1355

- Used nock to mock the Stripe API.
- Re-used the price fixture for the Stripe API mocks.
2022-02-16 14:23:59 +01:00
Thibaut Patel
43960b7de6 Removed a side effect in member tests
- Removed stubs after each tests
- Removed assignments to `_configured` as they lead to side effects is the stripe service is configured beforehands
2022-02-16 14:02:13 +01:00
Fabien 'egg' O'Carroll
8547ea05e0
Added test for checkout.session.completed (#14149)
refs https://github.com/TryGhost/Team/issues/1338

Testing the most basic signup flow for new paid members should give us a
good base to write other stripe webhook based tests.
2022-02-16 13:34:33 +02:00
Renovate Bot
4ebbe90f17
Update dependency body-parser to v1.19.2 2022-02-16 05:19:22 +00:00
Fabien 'egg' O'Carroll
dc78d273c3
Added stripe test assertions (#14150)
We've split the tests into two describes, one for when Stripe is enabled
and one without, because we setup Stripe in the before method.

We use nock to mock the Stripe server and assert that there is no call
to delete the subscription.
2022-02-15 21:00:06 +02:00
Renovate Bot
2b241b4e6a
Update dependency @sentry/node to v6.17.8 2022-02-15 16:28:10 +00:00
Hannah Wolfe
d4ed00831e
Updated fixture Casper@v4.7.2 & corrected README
- I noticed our test fixture theme was still throwing errors during tests because it had partials that are no longer in use
- Updated the docs on how to update Casper to include ensuring Casper was on a valid version AND removing Casper before
  copying it across
- Performed the exact steps in the README
- This ensures that the Casper version we use in our tests is not throwing tonnes of errors and is up to date
2022-02-15 15:42:14 +00:00
Fabien 'egg' O'Carroll
133a41c256
Added scaffolding for testing Members with Stripe (#14142)
refs https://github.com/TryGhost/Team/issues/1338

This adds some initial scaffolding to make it easier to test Members with Stripe
 - `mockStripe` method to disable the network, so we can use nock to intercept
Stripe API calls
- `setupStripe` method to be called _before_ getting an agent so that Stripe is 
configured
- `getMembersAPIAgent` to get an agent for the Members frontend API
2022-02-15 15:08:58 +02:00
Daniel Lockyer
b2e04cce4b Bumped all Members packages
- we've just fixed up the use of `@tryghost/errors` and bumped some
  dependencies in all of our packages in Members
- this commit bumps all of those packages in Ghost so we can stay
  up-to-date
2022-02-15 13:58:55 +01:00
Naz
09bf5804ad Fixed e2e-framework to correctly compare headers
refs https://github.com/TryGhost/Toolbox/issues/209
refs https://github.com/TryGhost/Toolbox/issues/210

- Fixed request header processing by the e2e-framework where it failed to lowercase incoming header keys. This bug made it harder to test code paths which involve header checking, e.g. following code: `req.headers['stripe-signature']` would not get a correct value if the header was specified as Stripe-Signature
- Additional output to the status code assertions was added - this allows to have more context when an invalid response code comes back in a test.
2022-02-15 18:38:45 +07:00
Fabien "egg" O'Carroll
f88b6bd02f 🐛 Fixed Stripe checkout session urls being invalid
refs https://github.com/TryGhost/Team/issues/1322

Since the Members service is no longer started when Stripe is
reconfigured the url config used for checkout sessions was not updated.

This moves all of the default Stripe urls into the Stripe service, where
they will be updated as/when Stripe is connected/disconnected.
2022-02-15 12:50:07 +02:00
Thibaut Patel
db6537fede Moved members importer tests to its own test file
no issue

- The members importer api tests don't use the e2e framework, so it's better to move them in their own file as we did for the e2e regression tests.
- Fixed a content-disposition header issue
2022-02-15 11:16:43 +01:00
Thibaut Patel
e59ee38d21 Updated the authentication test
no issue

- Mocked the github url with nock to avoid network usage during regression testing
- Added logging when the theme install fails during setup
2022-02-14 18:22:53 +01:00
Thibaut Patel
8dcf92d047 Disabled a failing test
refs 531ec579a2

- This test broke the build in commit 531ec579a2
- For some reason when running just the test file, it passes. When running the full e2e-api test suite, it fails.
- I'm commenting it to unblock the broken build and move on to other tests
2022-02-14 17:11:12 +01:00
Thibaut Patel
531ec579a2 Added missing tests from previous commit
refs 3288e5bf33

- These tests do not use the new e2e framework given it doesn't support file attachments yet
2022-02-14 14:43:34 +01:00
Thibaut Patel
3288e5bf33 Added e2e tests for members (with multipleProducts enabled)
refs https://github.com/TryGhost/Team/issues/1353 https://github.com/TryGhost/Team/issues/1356 https://github.com/TryGhost/Team/issues/1355

- Uses the new e2e test framework (snapshots)
- Part of the tests couldn't be converted as they use file attachments (unsupported by the new e2e test framework at the moment)
2022-02-14 14:14:03 +01:00
Djordje Vlaisavljevic
82eec9f6a5 Added membersTableStatus feature flag
refs https://github.com/TryGhost/Team/issues/1035
2022-02-14 13:00:04 +01:00
Renovate Bot
be5677cbd1
Update dependency eslint to v8.9.0 2022-02-14 02:20:41 +00:00
Renovate Bot
07ffe8fd94
Update dependency @sentry/node to v6.17.7 2022-02-11 18:01:11 +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
Hannah Wolfe
b5ee17b25f
Moved site.test.js from regression to e2e-api
- We're in the process of rolling out a new e2e-framework, and getting rid of the regression tests
- We'll eventually merge all the tests together and into using the same framework
2022-02-11 16:24:00 +00:00
Daniel Lockyer
cc466edd8f v4.36.0 2022-02-11 16:00:27 +00:00
Daniel Lockyer
4026150062 Updated Admin to v4.36.0 2022-02-11 16:00:27 +00:00
Thibaut Patel
de94190ad5 Renamed members API tests to legacy
refs https://github.com/TryGhost/Team/issues/1353

- Doing a renaming-only commit to avoid merge conflicts while I work on the new members.test.js test file
- The new `members.test.js` file will set the `multipleProducts` flag to true
2022-02-11 15:02:08 +01: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
Fabien "egg" O'Carroll
46db240bf9 🐛 Fixed welcome pages for paid signups
no-issue

The way we choose which email to send is too tightly coupled with the
magic link generation, which meant that when we added the new paid
signup email, the magic link looked like <url>?action=signup-paid rather
than <url>?action=signup - our welcome page logic was working off of
only using welcome pages for action=signup and so this broke.
2022-02-11 13:08:07 +02:00