Commit Graph

396 Commits

Author SHA1 Message Date
Hannah Wolfe
c80e68b93a
Updated all members tests to use mockManager
- This part of the framework can be used in isolation
- Using mockManager everywhere makes it more visible how to use it
- Aside: fixed .getAdminAPIAgent not needing a URL in site tests whilst cleaning up
2022-02-10 12:21:05 +00:00
Thibaut Patel
26c6238c3b Released to GA the theme parameter in the /authentication/setup route
refs daeb06e835

- This is an additive change, and the parameter is optional so it's better to ship it right away (testing was hard as it's a chicken and an egg problem to have a feature flag in the setup route).
2022-02-10 12:21:28 +01:00
Hannah Wolfe
c885dac30a
Removed chai + misc auth test cleanup
refs: https://github.com/TryGhost/Toolbox/issues/158

- We only use chai in a handful of places now, and it seems totally unnecessary
- Use assert instead
- Made other minor changes with a view to this being a reference aka "perfect" test suite
2022-02-09 21:14:31 +00:00
Hannah Wolfe
da44ccaf11
Removed querystring dep from members tests
refs: https://github.com/TryGhost/Toolbox/issues/158

- if we had to combine a large list of params then this would make sense
- we could/should also add a .query() method to our agent
- however, I don't think this is worthwhile/necessary for just 2 params right now :)
2022-02-09 21:14:17 +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
0711555cbd
Added mockLabsEnabled helper
refs: https://github.com/TryGhost/Toolbox/issues/158

- Cleans up the different ways that labs could be mocked into a simple helper
2022-02-08 20:31:02 +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
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
b2a5bc980e
Abstracted sentEmail assertions as part of mock utils
The idea here is to keep the concept of _what_ we're asserting (that an email was sent)
away from the implementation of how we check that assertion

This means that tests can have a consistent api like .sentEmail(), and if we change how that function works,
we only have to update the assertion function in the MockManager

Much more cleanup to come behind the scenes, but the aim is to make the tests as clean as possible
2022-02-07 17:28:53 +00:00
Hannah Wolfe
efdae70cbc
Updated members regression tests to use e2e framework (#14130)
- This is an example refactor to the new framework
 - This does not yet include snapshot testing (coming SOON)
2022-02-07 17:15:55 +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
Thibaut Patel
daeb06e835 Added a theme parameter to the /authentication/setup route
refs https://github.com/TryGhost/Team/issues/1296

- The `theme` must be a github `org/repo` string
- This uses the internal API instead of the services because the API has extra implementation details not present in the services.
2022-02-07 12:03:40 +01:00
Hannah Wolfe
88d1d1d4a0 Split members importer and members tests
- This is so that we can start refactoring more tests to use our new e2d framework
- That framework doesn't support file uploads yet, so tests with uploads are split out
2022-02-06 18:02:56 +00:00
Hannah Wolfe
499f2e852e Removed canary folder from regression tests
- we no longer have any concept of testing other versions than canary, therefore this folder doesn't mean anything
2022-02-06 18:02:56 +00:00
Hannah Wolfe
c9ca388a9f
Added new express-test framework to our ref tests (#14117) 2022-02-06 16:18:12 +00:00
Hannah Wolfe
0bf9d6f642
Renamed request to agent in tests
- I _think_ this makes it easier to read and understand what's happening
2022-02-04 17:19:48 +00:00
Rishabh
7959aeed55 Updated tests for default content visibility
refs https://github.com/TryGhost/Team/issues/1071
2022-02-04 19:56:11 +05:30
Rishabh
c99ee980af Added migration to transform default tiers visibility from nql string
refs https://github.com/TryGhost/Team/issues/1071

Default content visiblity for specific tiers is now stored split between `default_content_visiblity` and `default_content_visibility_tiers` setting, with former storing the value as `tiers` and the latter stores the list of tiers that the visibility is restricted to. This migration transforms all existing sites that have default visibility stored as an NQL string from previous versions to follow the new model and store correctly on the new setting.
2022-02-04 19:56:11 +05:30
Rishabh
6f89ccf901 Added default_content_visibility_tiers setting for default tiers visibility
refs https://github.com/TryGhost/Team/issues/1071

Default content visibility for a post can be one of `public|members|paid|tiers`, where `tiers` denotes visibility restricted to specific tiers. This change adds a new setting to store the tier ids when default content visibility is set to `tiers`. This closely matches how the visibility is stored on `posts` table as well, with `visibility` stored as `tiers` and tiers data is stored on tiers pivot table.
2022-02-04 19:56:11 +05:30
Rishabh
c530ac2a92 Updated admin api schema to include tiers for post/page
refs TryGhost/Team#1071

- new `tiers` key is now attached to posts/pages API response to include tiers visibility
- updates expected response for post/page in tests to include `tiers`
2022-02-01 11:13:51 +05:30
Hannah Wolfe
2ea7d5432b
Updated casper test fixture to latest version
closes: https://github.com/TryGhost/Toolbox/issues/193

- Our Casper fixture was several years out of date.
- I'd already updated the ghost-api to point to the latest API version, which was the main difference
- This makes sure the full fixture is up to date and correct, and therefore that we're truly testing if Ghost right now works
- It also adds instructions for how to update it in future

GOTCHA: the mock-express-style tests are failing if the API difference between test-theme and casper are different
- I've tried to look into why this is - it's something to do with the overridden route settings not working properly if the API version changes
- Given that we may not keep this style of testing AND we are definitely not keeping API versions, I'm ignoreing this for now
- To get around it, I'm setting both themes to be v4 API, so that Casper is exactly as in main
2022-01-25 14:10:53 +00:00
Hannah Wolfe
bd9f720a70
Upgraded remaining theme fixtures to canary API
refs: https://github.com/TryGhost/Toolbox/issues/168

- Upgraded the remaining themes to be pinned to the canary API
- This required one minor fix because the edit URL has changed for authors in v4/canary
- I also ripped out everywhere that the theme ghost-api version was being pinned to canary, as this was unreliable and only happening in a few places
- It's also going to be unnecessary code as soon as we finish changing to only having one API version
2022-01-24 21:55:13 +00:00
Hannah Wolfe
8319d73b0a
Fixed timing-dependent content gating test
- This test failed for me intermittently because the posts would be out of order
- I assume this is due to my super-powered M1 mac 😂
- This rewrite only aims to remove the dependency between the insertion order and the output order
- Everything else should be the same, and it still tests that the posts that are meant to be members only are exactly that
2022-01-24 21:55:12 +00:00
Hannah Wolfe
2768f5bb72
Removed ancient Casper fixture
refs: https://github.com/TryGhost/Toolbox/issues/168

- The fixture represented Casper at Ghost version 1.0 which pre-dated the introduction of the posts_per_page config in package.json
- When Casper was upgraded to 2.0 in the fixtures, the lack of pagination broke the e2e tests for pagination
- This change introduces proper code to stub and override posts_per_page rather than keeping and using the old casper-1.4 fixture
- It also required me to remove a handful of CSS-based checks which are no longer true in the new theme version, but also didn't really add anything to the tests
2022-01-24 12:24:51 +00:00
Fabien 'egg' O'Carroll
a3182a7664
Removed Stripe Service regression test (#14050)
no-issue

This test should have always been a unit test, but it now no longer
serves a purpose, as we do not rely on the event being emitted - it
would also not break Ghost if the event _was_ emitted, so we should not
be testing for that.
2022-01-24 13:35:19 +02:00
Hannah Wolfe
2b6fcf9a8f
Improved naming of mock express tests
- these used incorrect case and unnecessary nesting
- they are now consistently named with our preferred patterns
2022-01-21 20:37:48 +00:00
Hannah Wolfe
4c8ff38a44
Updated misc unversioned tests to run on canary
refs: https://github.com/TryGhost/Toolbox/issues/168

- All of our unversioned tests should be running against canary already
- These tests are erroneously running on the wrong version

We're going to be dropping the idea of having multiple versions of the API in each Ghost version.
Because this has not achieved the goal of making it easier to make breaking changes, but it has
created an ordinate amount of technical debt and maintenance overhead.

As we know this is going away in the next major, there is no benefit to us constantly running tests
that check if those versions still work, especially given how long they take.

Instead we're starting work to ensure that all of our test work on canary, and that canary has
excellent test coverage so that we can be sure that our one API version works really well and that
any changes, no matter how subtle are deliberate, tracked and understood.
2022-01-21 15:11:48 +00:00
Hannah Wolfe
12e8c974a1
Cleaned up weird refs to versions in tests
refs: https://github.com/TryGhost/Toolbox/issues/168

- These are all places where we reference an API version like v2 or v3 but it's not actually
used or relevant.
- The aim is to get rid of all mentions of these old versions to make it clearer that we're only running tests on canary
2022-01-21 15:10:03 +00:00
Hannah Wolfe
7102c0ca82
Removed all the obvious tests for v2 & v3
refs: https://github.com/TryGhost/Toolbox/issues/168

We're going to be dropping the idea of having multiple versions of the API in each Ghost version.
Because this has not achieved the goal of making it easier to make breaking changes, but it has
created an ordinate amount of technical debt and maintenance overhead.

As we know this is going away in the next major, there is no benefit to us constantly running tests
that check if those versions still work, especially given how long they take.

Instead we're starting work to ensure that all of our test work on canary, and that canary has
excellent test coverage so that we can be sure that our one API version works really well and that
any changes, no matter how subtle are deliberate, tracked and understood.
2022-01-21 12:49:05 +00:00
Fabien 'egg' O'Carroll
a565da06b2
🐛 Fixed Offer Redemptions being over counted (#13988)
refs https://github.com/TryGhost/Team/issues/1257

Offer Redemptions were being overcounted due to the way we were updating
Stripe configuration for the Members service. We would create a new
instance of the members-api, which would have event handlers for
creating Offer Redemptions - by creating a new instance each time Stripe
config changed, we would overcount them.

Here we've pulled out Stripe related logic into the Stripe service, and
updated it internally - rather than creating a new instance. This means
that we've been able to remove all of the logic for re-instantiating the
members-api.

- Bumped members-api & stripe-service
- Removed reinstantiation of members-api
- Used stripe service to execute migrations
- Updated Stripe Service to handle webhooks & migrations
- Used webhook controller from stripe service
- Used disconnect method from stripe service
- Removed unused stripe dependency
- Removed Stripe webhook config from members-api
2022-01-18 17:56:47 +02:00
Rishabh
62777d7f26 Handled default product to use first paid product
Since we now have 2 products by default for all ghost sites, free and default paid, the usage of default product which so far was using first product needs to be updated to use the first paid product.

- updates default product usage to use first paid tier
- updates tests
2022-01-17 22:59:34 +05:30
Fabien 'egg' O'Carroll
10c214c148
Switched AMP to be 'off' by default in all new Ghost instances (#13907)
refs https://github.com/TryGhost/Team/issues/1189

Support for AMP is slowly in decline, and makes developing new cards trickier,
since AMP no longer has an effect of SEO we're going to disable it by default
as a first step toward moving away from it.

Co-authored-by: Thibaut Patel <thibaut@ghost.org>
2022-01-14 18:55:48 +02:00
Kevin Ansfield
96ec60e393
🐛 Fixed "Create Post" action error in Zapier when assigning new tags (#13972)
closes https://github.com/TryGhost/Zapier/issues/56

- fixes tag creation when creating posts with `tags: [{slug: 'new'}]` which should be supported
  - assigning tags with only `{slug: 'new'}` was triggering our validation for the required `name` property then bubbling up to the `bookshelf-relations` library resulting in a 500 error
  - the fix applied here is to set the `name` field to the same as the `slug` field if a name is not provided
2022-01-14 13:37:20 +00: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
5a150cc3b6 Removed duplicate snapshot initialization code
refs https://github.com/TryGhost/Toolbox/issues/158

- Allows for much smaller amount of code to configure a test to work with chai-jest-snapshots. They now work automatically for all regression tests and could be enabled for other suites by adding the "--require=./test/utils/snapshots.js" parameter in respective test:* package script
- Regenerated snapshot for authentication test as the naming structure
changed a little with the snapshot metadata being taken on a higher
level in the test (uses the suite name instead of a specific describe it
used to be called from)
2021-12-10 06:37:31 +13: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
307e4c2643 Removed unused test utils
refs https://github.com/TryGhost/Toolbox/issues/129

- These have been substituted by e2e-framework module
2021-12-09 22:20:54 +13:00
Naz
4fa9f07d66 Cleaned up Authentication API test suite
refs https://github.com/TryGhost/Toolbox/issues/129

- Rejigged the tests to use consistant async/await syntax. Looks so much more readable now!
2021-12-09 22:20:54 +13:00
Naz
59b0c0bb4d Integrated chai-jest-snapshot into authentication suite
refs https://github.com/TryGhost/Toolbox/issues/129

- This is an example of how the converted test suite syntax could look like when using jest snapshots.
- The tradeoff is not that visible just yet as these tests were mostly checking few fields, but when the whole range of admin API tests is convered we'll be able to get rid of the "checkResponse" utiliti methods along with all the supporting luggage!
2021-12-09 22:20:54 +13:00
Naz
3dfab7d682 Integrated chai-jest-snapshot
refs https://github.com/TryGhost/Toolbox/issues/129

- Minimal version of chai-jest-snapshot with property matcher support. It runs off the forked version of https://github.com/suchipi/chai-jest-snapshot
2021-12-09 22:20:54 +13:00
Naz
743b7a16e0 Refactored authentication and site tests to use e2e-framework
refs https://github.com/TryGhost/Toolbox/issues/129

- Provides an example of how to use the e2e framework.
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
Naz
a18fa18ff3 Fixed authentication test suites
refs https://github.com/TryGhost/Toolbox/issues/152

- This refactor fixes the rest of authentication test suite and outlines the state setup steps that are absolutely needed for tests that rely on any db state. It's still counterintuitive why the fixture initialization has to be called and in that specific order, so next will be refactoring in this area to simplify the initi code
2021-12-09 22:20:54 +13:00
Naz
25d75f69db Made options parameter in agetnt utils explicit
refs https://github.com/TryGhost/Toolbox/issues/152

- Passing around plain options object tends to become quite unreadable long term. While these new utils are being shaped up it's still easy to change interface and introduce new parameters with time as needed.
2021-12-09 22:20:54 +13:00
Naz
05a4fbfd2a Refactored request initialization with supertest
refs https://github.com/TryGhost/Toolbox/issues/152
refs 5bea089dfe
refs 16ad5f73c4

- The refactor is heavily inspired by the referenced commit from @ErisDS
- This refactor is meant to serve as a template for further refactors and unification of the abstraction over "request". Should allow us to be more agnostic towards the library that's powering the request thing. For example, mock-express style of request handling could substitute or get substututed easily if all tests are behind similar "get(Authenticated)Agent" interface
2021-12-09 22:20:54 +13:00
Naz
b7231875a0 Refactored authentication test suite to serverless boot
refs https://github.com/TryGhost/Toolbox/issues/152

- This is a continuation of an experiment to switch over to serverless boot in regression tests. Just a proofe of concept that authentication scenarios would also work and the expectations don't collapse unexpectedly.
- Nothing too crazy so far, easy and straight forward substitution of the config "url" with an express app passed to the supertest agent
2021-12-09 22:20:54 +13:00
Naz
4a1bee0a01 Reworked site regression test suite to serverless boot
refs https://github.com/TryGhost/Toolbox/issues/152

- Being able to set up test suites without blocking a port opens a door to new ways to run tests - for example this has been one of the blockers for running mocha tests in parallel
- Additional benefit is lighter statrup, which reducec the test execution time slightly. Doesn't seem like much but these things stack up!
2021-12-09 22:20:54 +13:00