Commit Graph

1243 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Rishabh
56a8d21263 Added unit tests for content gating post access
refs https://github.com/TryGhost/Team/issues/1343
refs 3ccd3601b3
2022-02-11 14:26:04 +05:30
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
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
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
Thibaut Patel
479df36a48 Added the last_seen_at column to members
refs https://github.com/TryGhost/Team/issues/1304

- This migration adds a column to store when a members was last seen
- The utils.js e2e test file was refactored according to the commit 06dd9bac59
2022-02-09 11:57:45 +01:00
Fabien 'egg' O'Carroll
88786f768b
Added validation for Tier prices
refs https://github.com/TryGhost/Team/issues/1319
refs https://github.com/TryGhost/Team/issues/521

This updates the members-api to explicitly validate Tier prices rather
than deferring to Stripe and using whichever errors they throw.
2022-02-09 11:04:58 +02: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
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
Daniel Lockyer
828a5d4d5a Restored quick database reset method via table truncation
refs a3cc66be50

- in the referenced commit, I made a util to speed up resetting the DB
  for SQLite by copying the database file
- I inadvertently removed an optimization we had before - where we
  truncate the tables and insert the fixtures instead of dropping the
  entire database
- this would be missing on MySQL tests
- this seems to have a big difference so this commit re-adds the
  optimization in
2022-02-07 21:27:10 +01:00
Hannah Wolfe
e6cddeca72
Fixed IDE derp with requring assert
- I don't know how this happened or why it worked locally :woman-shrugging::skin-tone-2:
- seems like my IDE did a fart and I didn't notice.
2022-02-07 19:45:33 +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
Torsten Zander
f1b71f7fd7
🐛 Fixed AssetHelper not working with svg (#13978)
loses TryGhost#13971

This fixes an issue with links containing # anchor. It makes sure the # part is at the end of the url like url?v=hash#anhor

Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-02-07 15:07:18 +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
Fabien 'egg' O'Carroll
d60d24e744
Migrated email filter columns from VARCHAR to TEXT (#14091)
refs https://github.com/TryGhost/Team/issues/1287

Currently we have a hard limit of how large an email filter can be,
which is very restrictive once a site starts using Tiers - by moving
toward a TEXT column, we essentially give the filters unlimited size.

This currently doesn't handle SQLite as there are no limits on VARCHARS
in SQLite.

The down migration is a loop so we don't have to handle values larger than
50 characters
2022-02-04 16:09:35 +02:00
Fabien 'egg' O'Carroll
805c9f22f5
Added e2e test for comping Members (#14094)
no-issue
refs https://github.com/TryGhost/Members/commit/6860e3c1
refs https://github.com/TryGhost/Members/commit/03a6d694

This adds an e2e tests for the regression we had with comping members.

The stripe service imports the members service, which will instantiate
members-ssr once it is loaded, which will use the uninstantiated
settings cache resulting in errors due to a missing theme_session_secret.

For this reason we require the stripe service inside of the test function,
rather than at the top level of the file
2022-02-01 18:57:27 +02:00
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
Rishabh
64721150a9 Updated tests to handle visibility tier
refs https://github.com/TryGhost/Team/issues/1071

- updates tests to handle new visibility of `tiers` which uses tiers pivot table
2022-02-01 11:13:51 +05:30
Rishabh Garg
eeafc8603b
Added pivot table to store tiers on post (#14038)
refs https://github.com/TryGhost/Team/issues/1071

We used `posts.visibility` originally to store visibility as `free|paid` with a character limit of 50. This same field was repurposed to store an NQL filter when member tiers is enabled. The NQL filter uses the slug of the tier name, which can easily create a filter longer than 50 characters, adding an unwanted limitation on number of tiers that can be added to post's visibility.
Going forward, we'd like to store the visibility of posts for tiers in a separate pivot table and instead store the value of `visibility` as `tiers` when restricting post access to specific tiers. This change -

- adds a new pivot table fixture for storing relation between posts and tiers
- adds a migration for creating the new table
- updates tests
2022-01-31 15:33:58 +05:30
Fabien 'egg' O'Carroll
8393c1e90a
Added welcome_page_url column to products table
refs https://github.com/TryGhost/Team/issues/1168

Rather than using a single url for paid signup redirects, we want to
support setting a welcome page on a tier by tier basis. This column will
be used to store the URL. A text column of length 2000 is how we have
stored URL's elsewhere in the schema.
2022-01-26 11:44:40 +02:00
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
a5655c4a22
Removed unnecessary files from casper fixture
refs: https://github.com/TryGhost/Toolbox/issues/193

- The Casper fixture in the codebase is copied to a tmp folder structure every single time we start Ghost in an e2e test
- We shouldn't keep files here that don't actually get used!
- The files I'm removing are src files, used for building, but we already have the built files
2022-01-25 14:07:59 +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
034f7d9a55
Renamed & cleaned up price data test theme fixture
refs: https://github.com/TryGhost/Toolbox/issues/168

- Having large theme fixtures makes tests run slower, so we're working to reduce them
- This fixture was a full copy of a very old version of Casper, but all we needed was a handful of files so that the tests can run
- This theme is also used for testing members, not just price data so I've renamed it for clarity
- The remaining files is the bare minimum we need to test these features
2022-01-24 09:55:21 +00: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
9d8089a748
Removed deprecated routes.yaml data format
refs: https://github.com/TryGhost/Ghost/issues/10434
refs: https://github.com/TryGhost/Ghost/pull/10449
refs: https://github.com/TryGhost/Ghost/pull/10559

- We originally had a weird structure returned for data keys in routes.yaml.
- To the best of my knowledge this was never desired or really used
- I'm removing it now simply because I'm trying to remove all references to v2/v3 in tests, and this had a comment saying it was deprecated in v3
- I could have changed the comment to be a proper @deprecated comment and leave this til we rewrite dynamic routing
- However it's weird and confusing and I believe entirely unused - so getting rid is way way better
2022-01-21 20:16:43 +00:00
Hannah Wolfe
fc6d60e36d
Updated test UrlUtils to use canary by default
refs: https://github.com/TryGhost/Toolbox/issues/168

- This file was pinning various tests to v3

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:12:27 +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
e47b55b466
Removed some hidden v2 and v3 tests
refs: https://github.com/TryGhost/Toolbox/issues/168

- These are all test files I missed in ffcd3fbe313b4a413833da9a7473376cb21246fd

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:07:17 +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
Hannah Wolfe
7c7e38f8e8
Fixed overly specific default routes test
- This test failed after updating Casper, because Casper has changed how it outputs next/previous type posts at the bottom
- This test was overly specific. If we want to test if the next and previous posts are output, we should have a particular assertion/test that clearly does that
- I've changed the test to not use cheerio and just do a couple of checks to make sure that head and body contain something sensible
- This will still be specific to the fixtures though
2022-01-21 12:31:45 +00:00
Fabien "egg" O'Carroll
26ef4afdb9 🐛 Fixed config API not returning boolean
no-issue

The mailgunIsConfigured config should be a boolean, rather than a string/undefined/null.
2022-01-20 18:25:41 +02:00
Fabien 'egg' O'Carroll
534ebecc19
Added active column to products table (#14016)
refs https://github.com/TryGhost/Team/issues/1252

We need a way to signal whether or not a Tier is active or archived, and
we'll be using the active flag in the same way we do for Offers.
2022-01-20 15:50:18 +02:00
Marat Vyshegorodtsev
74b97e99cd
Added timezone and locale to the options of the date helper (#13892)
fixes https://github.com/TryGhost/Ghost/issues/13832

The `date` handlebars helper has only one option currently — `format`. It assumes the locale and timezone from the `options.data.site` object which is not always desired behavior.

The helper sometimes is used, for example, in custom RSS template where we always need the `en-US` locale, not the one that we have configured for the website globally. This change makes the two options configurable, and defaults to the `options.data.site` object values, if not specified in the helper (keeps the backwards compatibility with the current behavior).
2022-01-19 14:43:53 +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
Fabien "egg" O'Carroll
b3c12bd435 Fixed Members importer tests
no-issue

These tests were incorrectly checking for a subscribed value of true,
and thus failed to catch the bug fixed in the previous commit. The tests
now reflect the intended behaviour.
2022-01-11 16:44:12 +02:00
Thibaut Patel
01e833376b
🐛 Added pagination to sitemap.xml to avoid max 50,000 entries limit
refs https://github.com/TryGhost/Team/issues/1044
refs https://github.com/TryGhost/Ghost/pull/13298

- This splits the sitemaps according to the limit set by Google https://developers.google.com/search/docs/advanced/sitemaps/large-sitemaps

Co-authored-by:
- Kevin Ansfield (@kevinansfield)
2022-01-05 11:54:35 +01:00
Sam Lord
af075c063e Revert "Improve the performance of prepareContentFolder"
This reverts commit bfacca3035.
2022-01-04 11:34:42 +00:00
Sam Lord
bfacca3035 Improve the performance of prepareContentFolder
refs: https://github.com/TryGhost/Toolbox/issues/150

Instead of loading all themes for each set of tests in the e2e suite, only load the frontend at all for frontend tests, and only load themes for the theme tests.
2022-01-04 09:27:04 +00:00
Matt Hanley
cc7f527a6a
🐛 Added fallback for meta_description to custom_excerpt (#13927)
closes https://github.com/TryGhost/Ghost/issues/13920

- Custom excerpt should be used as a fallback for meta_description in line with the behaviour of OG and Twitter metadata
- We specifically don't want to use the full fallback to the auto-generated preview text when a custom excerpt isn't defined, because we trust search engines to be able to summarise content better than we can
2022-01-03 19:09:03 +00:00
Kevin Ansfield
cabf78e938 Cleaned up customThemeSettings labs flag
closes https://github.com/TryGhost/Team/issues/1164

- `customThemeSettings` feature is GA so any conditionals can be cleaned up
- removed conditional loading of custom theme settings and associated API routes
- removed event trigger for reloading custom theme settings when the feature flag is toggled
- removed flag from labs GA list
2022-01-03 17:45:25 +00:00
Fabien 'egg' O'Carroll
bc75d20cef
Updated SingleUseToken grace period to 10 minutes (#13926)
refs https://github.com/TryGhost/Team/issues/1216

Some email security clients are scanning links at delivery, rather than
at the point the user clicks on them. This is causing magic links to
expire. To get around this we're increasing the grace period in which a
link can be used multiple times to 10 minutes.
2022-01-03 17:55:53 +02:00
Fabien 'egg' O'Carroll
0c853a372b
Supported restricting limit="all" in get helper (#13903)
refs https://github.com/TryGhost/Team/issues/1251

With sites that have a huge number of resources, using limit="all" can
cause OOM errors at the Node level. Administrators now have the ability
to cap limit="all" requests via config. This only affects the get helper
used in themes, not the API, this is by design as themes have less
visibility of issues.
2021-12-16 13:59:39 +02:00
Sam Lord
97c68dd388
Replace error handler middleware with @tryghost/mw-error-handler (#13879)
refs: https://github.com/TryGhost/Toolbox/issues/137

Extract error handling middleware and replace with a package.
2021-12-14 15:18:46 +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
42cd78e05e Added coverage for route settings class
refs 3150c87935

- Adds basic coverage for a bug that was fixed in referenced commit.
Next time it should be easier to add more tests to the suite as there's
already an example starter to work your way from.
2021-12-13 12:21:47 +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
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
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
af8387d1f4 Fixed handing test suite
no issue

- The response from the server might not always contain an array with errors (for example when there's a generic 503 error). This changes prevents tests from hanging and adds at least some relevant output
2021-12-09 13:52:02 +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
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
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
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
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
Daniel Lockyer
2d090b8b2a Revert "Remove unnecessary references to ghostVersion"
This reverts commit 443ee369d2.
2021-12-08 14:28:41 +00:00
Sam Lord
443ee369d2
Remove unnecessary references to ghostVersion
refs: https://github.com/TryGhost/Toolbox/issues/146
GhostVersion was passed in here but not used at all. This just removes those unnecessary usages.
2021-12-07 13:48:22 +00:00
Daniel Lockyer
4673bd05fc
Destroyed connection before restoring DB file
no issue

- we've seen some instances of SQLite saying "database disk image is malformed"
- I think this happens because we copy the file whilst we are still connected to
  the old DB
- this commit destroys the connection before copying the clean file to the live
  DB file
2021-12-07 08:23:51 +00:00
Naz
9c0752896c Fixed error wording in fixture-utils
refs 404b2023e5
refs https://github.com/TryGhost/Toolbox/issues/129

- The previous error message wasn't helpful at all . Now we can tell "what?" fixture was looked-up and then go from there to find out why it is missing
2021-12-07 11:12:10 +04:00
Daniel Lockyer
a3cc66be50 Copied DB for faster SQLite tests
refs https://github.com/TryGhost/Toolbox/issues/136

- we nuke and reinitialize the DB many times between tests
- this forms a good portion of the time taken and we shouldn't be spending
  so much time on just resetting the DB back to a known state
- this commit switches out the knex-migrator reset + init calls for SQLite to
  a function which keeps a clean copy of the DB and copies the file back
  when we "reset"
- for MySQL, existing functionality is kept
- this massively speeds up tests because it saves ~700ms+ for every reset
- whilst this change seems to work, it's just the start so there's a
  lot more refactoring needed. this change is currently gated to CI until
  it's deemed safe/sane enough to run on local machines without blowing
  up
2021-12-06 15:22:44 +00:00
Hannah Wolfe
40fee069c9
Moved locale testing out of casper fixture (#13850)
refs: https://github.com/TryGhost/Toolbox/issues/137#issuecomment-986829141

- Moving the weird customisation of Casper out of the test fixture
- Created a standalone theme for testing locales instead
- This should make it easier for us to update our Casper fixture
2021-12-06 15:11:54 +00:00
Naz
3c19a8f014 Cleaned up mock-express tests from unnecessary inits
refs https://github.com/TryGhost/Toolbox/issues/152

- Have skimmed through the test suites in hopes to find some quick performance wins to bring the runtime speed closer to the one in "main". Haven't been successful to identify major wins, cleaned up a couple of small bits.
- We'll have to live with a tradeoff between maintainability/unified boot VS cost of mainitaining a fake boot process. Imo extra couple seconds of runtime is worth it.
2021-12-06 21:28:53 +13:00
Naz
a58e9bb61c Added default options to regression test utils
refs https://github.com/TryGhost/Toolbox/issues/152

- Allows to override boot options form regression test level - needed in some cases for vhost tests
2021-12-06 21:28:53 +13:00
Naz
9dc096cb15 Fixed api vs frontend test suites
refs 3c7a8dead4

- The tests needed adjustments with the native boot mechanism.
- The number of returned posts changed in the test resutls because duing native boot we also insert fixtures which add to the number of initial posts
- The vhost regression suite is still failing and I had no strength to figure out why. The redirect it fails with makes no sense, the clue here is that the test doesn't fail when running in isolation, so probably has to do with some leftover overrides from the previous test cases.
2021-12-06 21:28:53 +13:00
Naz
9e53f36c42 Fixed regression test suite stubs
refs 3c7a8dead4

- The boot process has been using an asyc method to load the routes file, which is the case now for these tests since the switch to raw boot method instead of mimicking it manually
2021-12-06 21:28:53 +13:00
Naz
51a4a65eec Enabled frontend-only boot for mock-express tests
refs 3c7a8dead4

- Simplifies the state initialization code significantly and reuses native boot mechanism instead of mimicking it (it was a headache to maintain with all the internal services moving around)
2021-12-06 21:28:53 +13:00
Daniel Lockyer
f2ba9d3aac
Fixed notify library tests
refs ec28478435

- the method signature changed in
  9fa8800b9d
  and the usage wasn't updated in Ghost
- this commit updates the tests to reflect this internal change
2021-12-06 08:20:39 +00:00
Thibaut Patel
faff6ad669 Fixed the tests from the previous commit
refs 77c0364efd
2021-12-02 10:48:46 +01:00
Thibaut Patel
77c0364efd 🐛 Fixed malformed URLs crashing the url helper
refs https://github.com/TryGhost/Team/issues/960

- Character like "%%" or "%80" would crash our current url escaping behavior. We consider they aren't valid URLs as the percentages haven't been properly escaped.
2021-12-02 10:34:24 +01:00
Fabien egg O'Carroll
6b99f0382f Fixed tests for members importer
refs https://github.com/TryGhost/Team/issues/1202

This was incorrectly setting the subscribed value to false due to the
bug referenced
2021-12-01 17:41:07 +02:00
Thibaut Patel
e17446456e Fixed a test failing due to a .DS_Store file
no refs

- When a `.DS_Store` file was present, the code wasn't ignoring the `README.md` anymore. I've fixed it with a for+while nested loops.
2021-12-01 15:58:09 +01:00
Thibaut Patel
a1421c2380 🐛 Fixes oembed bookmark with whitespaces
refs https://github.com/TryGhost/Team/issues/1200

- The leading/trailing whitespaces are trimmed by `new URL()` but are considered invalid in metascraper. Trimming solves this edge case.
2021-12-01 15:58:09 +01:00
Naz
57de4aca71 Fixed mock-express test setup
refs https://github.com/TryGhost/Toolbox/issues/152

- The tests would fail without these initializations when run in isolation
2021-12-01 18:56:29 +04:00
Fabien egg O'Carroll
3407df7c1c Fixed stubbing of labs data
no-issue

Labs data is read from the labs service not the settings cache, so we
should be stubbing this to ensure that the tests run correctly.
2021-12-01 16:11:27 +02:00
Sam Lord
2887e416da
Switch to @tryghost/errors from ignition errors package (#13807)
refs: TryGhost/Toolbox#147

* Replaces all references to isIgnitionError with isGhostError
* Switches use of GhostError to InternalServerError - as GhostError is no longer public
There are places where InternalServerError is not the valid error, and new errors should be added to the @tryghost/errors package to ensure that we can use semantically correct errors in those cases.
2021-12-01 10:22:01 +00:00
Kevin Ansfield
8cb748c580 Changed tenor config API key name
refs https://github.com/TryGhost/Team/issues/1237#issuecomment-981770688

- API key names for external services now follow a standard pattern
  - top-level key of the service name
  - public/private and read/write perms inside the name, eg. `publicReadOnlyApiKey`
- updated test to match expected API key name
2021-11-30 11:27:28 +00:00
Naz
2540be63c1 Removed v2/v3 regression tests for non-stable endpoints
closes https://github.com/TryGhost/Toolbox/issues/148

- These regression tests introduce very little additional value in exchange for an expensive time to run them. Because we mostly care about stable support for the latest stable API version, the older API version test for "internal" API can go away
- In case there are bugs found we do care about in the v2/v3 APIs we can always revert some of these tests.
2021-11-30 13:31:49 +04:00
Naz
6aee35ec3d Fixed typos
no issue
2021-11-30 20:54:18 +13:00
Naz
2ed1d5c2cc Removed unnecessary resetGenerators call
no issue

- This extra call doesn't seem to be necessary during a fresh boot. It only adds noise in code!
2021-11-30 20:54:18 +13:00
Naz
21219fff2f Removed unused sinon referece
https://github.com/TryGhost/Toolbox/issues/140

- There is no need for sinon usage in this test suite
2021-11-30 20:14:51 +13:00
Naz
6e395291fe Moved custom routes test to e2e frontend suite
https://github.com/TryGhost/Toolbox/issues/140

- This test was bloating the regression/site suite and was using hacks (calling the Admin API) to create a custom redirects state
- It suits way better in e2e frontend test suite with less hacky approach to start the Ghsot instance  - using custom routes file path to initialize the instance
2021-11-30 20:14:51 +13:00
Naz
961c29dc72 Added test util to load instance with custom routes
https://github.com/TryGhost/Toolbox/issues/140

- Allows to fully start an instance with a custom routes.yaml file without a need to do workarounds - e.g. we used to call an internal Admin API from a regression test suite, which is not a good practice
-  Providing "routesFilePath" to startGhost method copies that file to the default settings location and start the instance with that configuration. No need to do API calls or check if the routing service "isFinished"
2021-11-30 20:14:51 +13:00
Naz
6b81b3db02 Unified RSS frontend tests
refs https://github.com/TryGhost/Toolbox/issues/140

- Same/similar RSS tests were present in regression and e2e tests suites. It made sense to move missing cases from regression to e2e. This saves us time bootstraping db state in multiple places and keeps all test cases regarding single feature in same place
2021-11-30 20:14:51 +13:00
Naz
449c61bb1b Removed unnecessary fixture setup in redirects e2e test
refs https://github.com/TryGhost/Toolbox/issues/139

- There's no need for extra users neither extra posts for this suite to run. Less fixtures to be setup - quicker the test execution
2021-11-29 17:53:33 +04:00
Naz
1619a0f49a Removed redirects site regression test suite
refs https://github.com/TryGhost/Toolbox/issues/139

- With ec2aed5ce8 the DynamiRedirectsManager has reached 100% test coverage and most of the tests present in the removed regression suite have been ported to unit tests
- No need to keep slow tests around! :)
2021-11-29 17:51:13 +04:00
Naz
ab9a470623 Removed dead code in redirects.test
refs https://github.com/TryGhost/Toolbox/issues/139

- This code was either not executed and did nothing useful for the test suite. Shaves off extra 2s from the test runtime
2021-11-29 11:55:13 +04:00
Naz
fc5984b486 Slimmed down redirects test suites
refs https://github.com/TryGhost/Toolbox/issues/139

- The regression test suite for redirects functionality for way too big. And each restart was causing massive overhead. It's enough to have a single exhaustive test using multiple input files
- The tests testing API endpoints should've been e2e tests to start with
- The rest is covered in the unit tests for redirects api service
2021-11-26 06:18:36 +13:00
Naz
125901b466 Added a test covering backup redirects functionality
refs https://github.com/TryGhost/Toolbox/issues/139

- This test is meant to partially substitute existing regression test suite for redirects
2021-11-26 06:18:36 +13:00
Naz
6ed5f64f4b Moved backup path calculation outside redirects module
refs https://github.com/TryGhost/Toolbox/issues/139

- Having tight coupling with backup file path calculation for redirects makes it extremely hard to test. In addition, having it injected will make it easier to swap this dependency to the mechanism similar to one used for routes files
2021-11-26 06:18:36 +13:00
Naz
3315ed34ae 🐛 Fixed redirects.json file corruption on upload
refs 91efa4605c

- Referenced commit introduced a double json-stringification to uploaded redirects.json files.
- The endpoint has no stability index of any sort and is meant to be dropped in Ghost v5. It's best to rework the redirects to the yaml format as descirbe here - https://ghost.org/docs/tutorials/implementing-redirects/#file-structure
2021-11-25 18:43:45 +04:00
Hannah Wolfe
621cfd9866
Moved admin redirect middleware to named file
- moving this middleware because we're about to add a second piece of middleware
- it's easier to see what we have when each middleware is in its own file rather than in one big middleware.js file
2021-11-25 14:29:17 +00:00
Daniel Lockyer
617fec71cb
Added number of server boots to test reporting
no issue

- this commit adds a counter for the number of boots we do in tests
- which therefore allows us to calculate the average boot time we
  experience
- only useful for debugging test performance
2021-11-25 09:52:30 +01:00
Naz
b3884a9c6f Removed v2/v3 redirects tests
refs https://github.com/TryGhost/Toolbox/issues/139

- The v2 and v3 redirects APIs are unofficial and should not be used by anyone in production. There's no good reason to maintain expensive to run test suites for old unofficial APIs.
- The test cases in canary suite covers the functionality of redirects enough to be sure they work as expeted
2021-11-25 11:59:31 +04:00
Thibaut Patel
a583f7236e Updated valid.zip to the latest casper version
refs c1006ec649

- This unblocks upgrading gscan. Some tests were failing due to the old fixture.
2021-11-24 20:22:20 +01:00
Naz
4811da45f2 Fixed redirects test suites
refs https://github.com/TryGhost/Toolbox/issues/138

- These tests still rely on the frontend to be present. Needs further investigation to remove "frontend: true" flag - it slows down test runs!
2021-11-25 03:20:47 +13:00
Naz
ac3b2e5aee Switched API regression tests to use frontendless boot
refs https://github.com/TryGhost/Toolbox/issues/138

- The boot oprimization gives a boost in the boot time, which should save time running regression tests
2021-11-25 03:20:47 +13:00
Naz
222273b66b Refactored regression tests to use async/await
refs https://github.com/TryGhost/Toolbox/issues/138

- Final batch of the refactor to async/await syntax.  Doing these refactors before modifying "testUtils.startGhost" everywhere to boot only with the backend
2021-11-25 03:20:47 +13:00
Naz
4cdcb16e49 Refactored regression users tests to use async/await
refs https://github.com/TryGhost/Toolbox/issues/138

- This is a continuation of a bigger refactor to use async/await syntax before migrating "startGhost" methods to only use backend boot
- Removed a little bit of dead code (like admin user creation) which should speed up test execution too!
- Refactored user variables to be declared closer to their usecases instead of being high up in a global scope - variables shoul not live that far apart from the code that uses them
2021-11-25 03:20:47 +13:00
Naz
b19a2ed2d7 Refactored regression tests to use async/await
refs https://github.com/TryGhost/Toolbox/issues/138

- First batch of the refactor to async/await syntax. Next one will cover the rest. Doing these refactors before modifying "testUtils.startGhost" everywhere to boot only with the backend
2021-11-25 03:20:47 +13:00
Naz
231cfef086 Removed use of ghostServer variable pattern
refs https://github.com/TryGhost/Toolbox/issues/138

- There is no good reason to keep this extra variable around just call "stop" in couple very specific cases. Even for those cases, there's `testUtils.stopGhost` method which achieves the same without additional variable to track.
2021-11-25 03:20:47 +13:00
Naz
8dd33c5034 Removed "ghost = testUtils.startGhost" pattern
refs https://github.com/TryGhost/Toolbox/issues/138

- Having the "ghost" alias only added cognitive load when reading through the test code and didn't provide any additional value. Removed the pattern to keep things simpler and more explicit
2021-11-25 03:20:47 +13:00
Naz
e715c5b82d Refactored posts regressions suites to use common initialization syntax
refs https://github.com/TryGhost/Toolbox/issues/138

- Using asycn/await syntax is way more readable and allows to identify further reusable patterns in test initialization. This refactor also served as an exploreation around how the code looks like at this point
2021-11-25 03:20:47 +13:00
Hannah Wolfe
0799f02e80
Rewritten HTMLErrorRenderer w/o asset helper & template
refs: 2af9e2e12

- This new HTMLErrorRenderer is borrowed heavily from finalHandler
   - This is the module that express uses to render errors if there is no custom errorhandler
- It just renders a really simple html page wrapping err.stack in a <pre>
   - This results in a nicely formatted, but unstyled error page
- I also updated BasicErrorRenderer to use the same res.statusCode + err.stack pattern rather than err.message

Note: This error renderer is _only_ used for renderering errors on the `/ghost/` route
 - In almost all cases, errors here are rendered by Ember
 - The only error that can be rendered here is a missing template error see: 2af9e2e12
2021-11-24 13:01:06 +00:00
Naz
aee949bbf4 Removed unused parameter from isFinished method
no issue

- The disableDbReadyEvent variable does nothing here, no need to keep junk around :)
2021-11-24 05:32:20 +13:00
Naz
6ee94f66b4 Fixed invalid settings file path configuration
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- There were two separate instances of the SettingsPathManager in route-settings and settings-loader causing the configured paths missmatching on test environment. Because of this missmatch, uploading and resetting the routes.yaml file didn't work!
2021-11-24 05:32:20 +13:00
Naz
04ab59c859 Rewrote reload routes.yaml test to use async/await
no issue
2021-11-24 05:32:20 +13:00
Naz
f0b8e9693f Fixed loadRouteSettingsSync stubs
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- Because "loadRouteSettingsSync" method is now a getter function these stubs had to be changed to use a different syntax
- It's a lot of maintenance to do such renames, so if someone has to touch this exact place again it might be worth abstracting this mocking into a separate utility of some sort.
2021-11-24 05:32:20 +13:00
Naz
2fed8dbbd5 Moved all settings module bootstrap logic into init method
refs refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- The initialization outside the init method is causing problems when the configs are mocked during the test setup
2021-11-24 05:32:20 +13:00
Naz
6d6aa12afe Extracted routes.yaml path calculation into external package
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- The full logic for  file path calculation for routes.yaml has been duplicated in couple modules. It is aslo following similar pattern used in redirects services and should be reused there once those modules are touched
2021-11-24 05:32:20 +13:00
Hannah Wolfe
0ede559d5b
🐛 Fixed card asset init/reload behaviour
- Card asset reloading was incorrectly only happening if the API version changed 🙈
- In addition, having an init function was redundant, as theme activation happens on boot
- This meant that the card assets were being generated twice on boot
- Instead, we now only generate them on theme activation, which covers the boot case and simplifies all the logic
2021-11-23 12:53:58 +00:00
Hannah Wolfe
6e6a4822f2
Updated servePublicFile to honor v= cache keys
- Currently it's assumed that public files are 100% static
- With card assets, we're using it for files that are partially static, but can change between reboots and theme changes
- We already have a system for managing cache busting across theme changes and restarts - the ?v= key that is added via the asset helper
- This was already in place and used, but servePublicFile's internal cache didn't honor this key, and cached for the lifetime of boot
- This small change means that if a ?v= query param is present on a request for a public file, that we pay attention to it. Else we cache as before
2021-11-23 12:49:53 +00:00
Naz
9c77abebb5 Removed force start from themes test
refs https://github.com/TryGhost/Toolbox/issues/135

- Looking closer into the reason why the test was failing without "forceStart" revealed that the server only start  was overoptimized - "initServicesForFrontend" should be a part of a backend as those are generic theme services.
2021-11-22 17:47:44 +04:00
Naz
d3f899689a Removed unnecessary rewire call
no issue

- Having rewire here doens't do any difference and should not be used if absolutely needed. Usually using rewire gives a code "smell" so there's some sort of coupling that's going on and probably has to be addressed first
2021-11-22 14:53:16 +04:00
Naz
23ba543abd Removed forceStart in theme e2e tests
refs https://github.com/TryGhost/Toolbox/issues/135

- The reason the test **settings** test was failing when the force start flag was removed in the **custom themes** was the bridge! The bridge was trying to execute function on the frontend when the boot was done without initializing the frontend. The setting test was changing locale and the timezone which triggered events calling up on frontend components - we clearly don't want to do this when the instance is booted without the frontend
- To make event initialization conditional moved it to the "init". This way the event listeners are only set up when we boot with the "frontend" flag set to true
2021-11-22 14:51:23 +04:00
Naz
f0ae7592cf Removed unneeded mocks
refs https://github.com/TryGhost/Toolbox/issues/135

- These mocks were failing to execute but didn't make any difference in the test outcome
2021-11-22 21:56:32 +13:00
Naz
bbc93ff996 Renamed withBackend/withFrotned to backend/frontend
refs https://github.com/TryGhost/Toolbox/issues/135

- Shorter name still makes sense and the "with" might be causing confusion understanding what's gonig on during the boot time
2021-11-22 21:56:32 +13:00
Naz
149c100b4c Fixed frontend initialization in "mock-express" tests
refs https://github.com/TryGhost/Toolbox/issues/135

- Without sensible defaults the web app was not initializing either the backend nor the frontned parts of the application. Fixed the defaults so the problem doesn't happen again and optimized mock-express-style initialization to only initialize the frontend routing
2021-11-22 21:56:32 +13:00
Naz
9057ca0ee2 Skipped unnecessary frontend initialization
refs https://github.com/TryGhost/Toolbox/issues/135

- This optimization is expected to play a role in more consistent "backend-only" boot where the previous test state might have left over a different theme version which might cause in unwanted URL Services reainitializations.
- What has been happening here is the themes.test.js suite was uploading a theme with a v4 api and when the users api test suite loaded up it switched back to a default v2 theme, which caused routing reinitialization
- The root problem here  is the themese suite is leaving a mess behind so a "restartModeGhostStart" is not really possible anymore - this should be cleaned up separately
2021-11-22 21:56:32 +13:00
Naz
34b0196c0f Added writeDisabled flag to URL file cache
refs https://github.com/TryGhost/Toolbox/issues/135

- Allows to turn off overwriting urls/resources JSON file caches on testing environment. This is needed to have predictable state when running multiple test suites that stop the Ghost process and try to persiste URL cache.
2021-11-22 21:56:32 +13:00
Naz
ee4d2dd1a8 Extracted a local file cache class for URLs
refs https://github.com/TryGhost/Toolbox/issues/135

- This extracts the file storage knowledge out of the URL Service an allows to have optional features based on the environment - for example turning off writing cache for when running tests
2021-11-22 21:56:32 +13:00
Naz
155e96b044 Fixed undefined error
refs https://github.com/TryGhost/Toolbox/issues/135

- Not all callers provide the parameter, so an empty object default saves from unecessary "undefined" errors
2021-11-22 21:56:32 +13:00
Naz
640296f74b Changed the test environment to load withFrontend
refs https://github.com/TryGhost/Toolbox/issues/135

- The global default should stay the same as it used to be and we can introduce an override for "withFrontend:false" on casa-by-case or area-by-area bases
2021-11-22 21:56:32 +13:00
Naz
03be383d8b Renamed testUtils.startGhost to localUtils.startGhost
refs https://github.com/TryGhost/Toolbox/issues/135

- Going though local utils allows to have the "withFrontend: false" flag applied only to the e2e-api test suites. This way we can gradually introduce the no-frontend change across all test suites
2021-11-22 21:56:32 +13:00
Naz
9359ae923d Moved startGhost function to local utils
refs https://github.com/TryGhost/Toolbox/issues/135

- Having the proxy in local utils allows to disable frontend gradually in test suites instead of all at once (the latter approach didn't work out as too many other suites still depend on full frontend initialization)
2021-11-22 21:56:32 +13:00
Naz
008b6e0fae Optimized e2e-api tests using boot with no frontend
refs https://github.com/TryGhost/Toolbox/issues/135

- When running e2e-API test in most cases there's no need to boot Ghost instance with full frontend. This should improve the boot time which should reflect on the speed of running test suites
- The tests where the "forceStart" and "withFrontend" are used together indicate that there's still some work to do to fully separate frontend/backend boot line. The force start is also unnecessary, but was needed to reinitialize all services properly - should be investigated!
2021-11-22 21:56:32 +13:00
Naz
3b390639c4 Introduced booting from fixture url cache in test environment
refs https://github.com/TryGhost/Toolbox/issues/135

- To be able to reliably start ghost instance without a frontend the process needs access to urls/resources caches
- Storing the configuration in "paths" for now as there's no better place for it untill we are able to mock the content folder in pre-boot
2021-11-22 21:56:32 +13:00
Naz
5168d6a822 Updated urls/resources cache fixtures
refs https://github.com/TryGhost/Toolbox/issues/135

- These fixture had to be updated due to hardcoded ids introduced in the fixtures.json for test
- This allows to boot up a Ghost instance without recalculating urls for most common database states
2021-11-22 21:56:32 +13:00
Naz
8fd7733fdf Hardcoded id's in test fixtures
refs https://github.com/TryGhost/Toolbox/issues/135

- These fixtures needs id's to be able to form a stable urls and resources cache that would be used across all e2e tests when booting without a frontend
2021-11-22 21:56:32 +13:00
Naz
d7b7bd1b28 Updated Users API e2e tests to use 'posts' fixture
refs https://github.com/TryGhost/Toolbox/issues/135

- This way the test is performed on a "full" set of posts that will become unified within all e2e tests for performance optimization
2021-11-22 21:56:32 +13:00
Hannah Wolfe
592d02fd23 🐛 Fixed perms error when building public assets
closes: https://github.com/TryGhost/Ghost/issues/13739

- Ghost cannot write to the core folder in correctly configured production installations
- Built assets therefore need to be written to the content directory
- Ghost does not overwrite anything in the content folder as part of an upgrade, therefore static files that are provided by Ghost
  must still live inside /core
- So as a result, we now have core/frontend/public and content/public
2021-11-19 11:36:45 +00:00
Hannah Wolfe
79233b1181 Removed unnecessary load of settings
- seems to save about a second locally for me - I'll take it!
2021-11-19 10:47:21 +00:00
Hannah Wolfe
cc9e256b36 Added extra debug to test utilities
- Looking for places we can SAVE TIME running tests
2021-11-19 10:47:21 +00:00
Hannah Wolfe
80358266b2 Added perf-improving PRAGMAs in testing mode
- These two things are meant to improve performance at the cost of reliability.
- Perfect for testing, however I think they make a minimal impact on modern SSDs :(
- Still worth a shot to see if it helps with CI
2021-11-19 10:47:21 +00:00
Sam Lord
0692ddf57d Revert "Replace update user last seen middleware with package version"
This reverts commit 07f8c6efbb.

Revert "Remove unused unit test file"

This reverts commit f1798119d3.
2021-11-17 11:00:55 +00:00
Sam Lord
d4e0ae14f1 Force start in email route tests to pick up stubbed API
refs: https://github.com/TryGhost/Toolbox/issues/130

The API version stays at v2 unless we stub the getFrontendApiVersion method. But stubbing the method doesn't get picked up unless we actually restart Ghost.

TODO: Maybe change the default here so we don't need to restart Ghost just to test the current version's API
2021-11-17 10:51:46 +00:00
Hannah Wolfe
332beaaf90
Moved "vhost-utils" to config helpers
- These are simple functions that get data from config in a specific format
- They are also used by the topmost part of the application
- Config helpers seems like a reasonable fit to get them out of the web folder
- Functions have also been renamed to try to get them to make more sense
2021-11-17 08:37:08 +00:00
Kevin Ansfield
63b7ef7dc6 Added Tenor contentFilter setting to config
refs https://github.com/TryGhost/Team/issues/1217

- moved top-level `tenorApiKey` to `tenor:apiKey` and added `tenor:contentFilter`
- added base config to `defaults.json`
- updated `public-config.js` and API output serializer to use the new top-level `tenor` key
2021-11-16 17:42:26 +00:00
Sam Lord
620c12b05f Amend previous commit to prevent console.log
no issue

Large amount of unstaged changes prevented me from catching this
2021-11-16 17:12:39 +00:00
Sam Lord
a5484a0fe1 Fixed transaction logic in data importer
https://github.com/TryGhost/Toolbox/issues/130

The transaction no longer commits in the promise chain, which wasn't
valid logic for a transaction, since it is commited automatically when
the promise chain resolves, and rollsback automatically when the
promise chain rejects.

This makes code which fails during the transaction error in the right
place, instead of getting stuck here. (Especially good for writing
tests).

The tests for this code can now live in the integration folder.
2021-11-16 17:09:55 +00:00
Sam Lord
f1798119d3 Remove unused unit test file
no issue

Relates to previous commit
2021-11-16 16:05:50 +00:00
Hannah Wolfe
4f9b72ff43
Renamed middlewares to middleware consistently
- This is a minor bugbare, but it will affect some configuration I'm about to do for c8
- I've been wanting to do it for ages, middleware is plural all on it's own so it's an odd affectation in our codebase
- This also only exists in 2 places, everywhere else we use "middleware"
- Sadly it did result in a lot of churn as I did a full find and replace, but consistency is king!
2021-11-16 15:51:47 +00:00
Naz
8281388290 Hardcoded ids in the data generator
refs https://github.com/TryGhost/Toolbox/issues/116

- Allows to have deterministic routing on each start of the instance - can use cache when starting tests
- To make use of the new fixtures need to place them in the content/data
folder when the test suite is initialized, then the cache detection will
kick in and boot up the UrlService in a constant time intead of having
to check "urlServiceUtils.isFinished"
2021-11-17 04:29:55 +13:00
Hannah Wolfe
b781e47cb9
Changed to use different fixtures during testing
- this keeps production and test fixtures separate, so that changing the prod fixtures doesn't change the shape of our tests.
- we may still want to test that the production fixtures do what we expect, but that can be handled in a separate integration test, by specifically setting the fixture path
2021-11-16 14:03:42 +00:00
Hannah Wolfe
426c8bf918
Refactored fixtures to be loaded by fixture manager
refs: https://github.com/TryGhost/Toolbox/issues/133

- instead of just a collection of utils, we now have a class that manages fixtures
- this should allow us to change the path to fixtures, e.g. between prod/dev and test, so that different fixtures can be loaded by default
- also makes it easier to test the fixture manager code itself
2021-11-16 11:17:03 +00:00
Naz
0681953e1f Fixed test mocks for Url Service test suite
refs 042618fe93

- There's no longer "getValue" method passed around in UrlService, so the were unnecessary and did a wrong thing here :) Yey, less code!
2021-11-15 20:11:05 +04:00
Naz
382d2dbe94 Added missing router identified parameter in tests
refs 042618fe93

- The newly introduced identified were expected in the UrlService's intergration tests to fit new method signature
2021-11-15 19:56:28 +04:00
Naz
5a62253466 Removed "router" dependency from UrlGenerator
refs https://github.com/TryGhost/Toolbox/issues/127

- Passing around whole instance of a frontend router was an overkill when there are only 3 static pieces of information that needed to be loaded. Extracting the router out makes the UrlGenerator way more readable, tests slimer, and the memory footpring of the process should be slightly lighter
- The toString overloading didn't make sense at the time of this refactor, maybe if there's a concrete usecase we could resurect it in a form of passing in a router's name or something.
2021-11-15 18:32:34 +04:00
Naz
6e205a3f05 Extracted an explicit "permalink" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
- This is almost the last piece to free us up from the massive "router" object that has been passed around
2021-11-15 18:32:34 +04:00
Naz
677ea1073d Extracted an explicit "resourceType" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
2021-11-15 18:32:34 +04:00
Naz
ca2809d432 Extracted an explicit "filter" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
2021-11-15 18:32:34 +04:00
Naz
176c369620 Refactored UrlGenerator to use DI constructor pattern
refs https://github.com/TryGhost/Toolbox/issues/127

- This is a standard across the codebase which is good to follow for better testability
2021-11-15 18:32:34 +04:00
Kevin Ansfield
6431e1a01c
Exposed tenorApiKey via config endpoint if set (#13734)
refs https://github.com/TryGhost/Team/issues/1217

- add `tenorApiKey` to `publicConfig.config()
- update canary config endpoint output serializer to include `tenorApiKey` when the `gifsCard` labs flag is enabled
2021-11-11 18:07:19 +00:00
Fabien O'Carroll
e69d112c77 Added support for custom OEmbed providers
refs https://github.com/TryGhost/Team/issues/1211

In order to override the default OEmbeds for OpenSea NFT's we need a way
to provide out own OEmbed data. We will want this in future too for
custom Twitter embeds, so this has been built in a way which allows
extension.
2021-11-11 17:16:03 +02:00
Fabien 'egg' O'Carroll
7fae5b8341
🐛 Fixed setting Tier prices after changing Stripe accounts
refs https://github.com/TryGhost/Team/issues/1212

This now emits the event when the service is reconfigured, rather than
when we issue the reconfigure command, which causes the event and the
action to be run in the wrong order. This would then cause knock on effects
of having the database in an undefined state - with stripe data in not linked
to the current Stripe account.
2021-11-10 14:03:03 +02:00
Naz
98de2d4274 Cleaned up uncecessary "purpose" fields from tests
refs https://github.com/TryGhost/Toolbox/issues/95

- The purpose field is not used in any way on the backend, so there's no need to have it in tests for Media API either
2021-11-09 16:41:38 +04:00
Naz
9edd299905 Added audio upload support to Media API
refs https://github.com/TryGhost/Toolbox/issues/95
refs 4907b7bf1e

- We need support for audio media uploads to be able to used them in cards. The new supported formats are .mp4 and .wav
- Example source files downloaded from https://filesamples.com/
2021-11-09 16:39:33 +04:00
Naz
4721b75463 Moved `/media/thumbnail/ Admin API endpoint to /media/thumbnail/upload
refs  https://github.com/TryGhost/Toolbox/issues/120

- Changed endpoint name as it suits way better to the `/upload` postfix convention we use along with all other endpoints that support file uploads
2021-11-09 16:39:33 +04:00
Naz
61b82e3ae2 Added thumbnail upload endpoint to Media API
closes https://github.com/TryGhost/Toolbox/issues/120

- Allows to update and upload brand new thumbnail images for previusly uploaded media resources
- The endpoint is available udner alpa flag as part of Admin API at `PUT /media/thumbnail/`
- As an input accepts following parameters:
- *required* `file` field containing an image file
- *required* `url` field containing parent media file URL
- *optional* `ref` as a field to put in an ID to reference the resource on the client side

- The response has following format:
```
{
  media: [{
    url: 'http://127.0.0.1:2369/content/images/1991/11/nicevideo_thumb.png'
    ref: 'unique-id-420'
  }]
}
```
2021-11-09 16:07:23 +04:00
Naz
2a7ef77a7b Added ability to delete existing files through storage adapters
refs https://github.com/TryGhost/Toolbox/issues/120

- When editing an uploaded media thumbnail  file there'a need to remove existing thumbnail to keep media files:thumbnails 1:1. - Because the API client only has a public URL under which the resource is served it can only provide that as an API input, the `urlToPath` was also added to the base class of LocalStorageAdapter (it might be moved up to the BaseAdapter in the future if we see a need)
2021-11-09 16:07:23 +04:00
Naz
fb8005f6e2 Refactored media tests
refs https://github.com/TryGhost/Toolbox/issues/120

- Introduced a new describe block before adding tests for a new endpoint
2021-11-09 16:07:23 +04:00
Naz
a099073fde Added Files API behind an alpha flag
refs https://github.com/TryGhost/Toolbox/issues/114

- Files API is meant to be used for non-executable file uploads of all sorts
- The files are stored and retrieved for download as-is
2021-11-08 11:40:17 +04:00
Naz
f43eeacfd0 Changed thumbnail to be an optional parameter
refs https://github.com/TryGhost/Toolbox/issues/95

- With incoming support of audio media files thumbnail would not be a required parameter
2021-11-05 17:17:18 +04:00
Naz
65d79f4a74 Fixed failing test
no issue

- Not sure what the purpose of this test is. Seems like it's kind of like an db integrity check where it makes sure the change is double checked before commiting
2021-11-05 17:17:18 +04:00
Naz
ad2583530a Renamed getLocalFileStoragePath
refs https://github.com/TryGhost/Toolbox/issues/95

- getLocalImagesStoragePath makes a lot more sense in context of what the method really does
2021-11-05 17:17:18 +04:00
Naz
c802097b72 Renamed LocalFileStorage to LocalImages store
refs https://github.com/TryGhost/Toolbox/issues/95

- This naming corresponds way better to what the actual adapter does
2021-11-05 17:17:18 +04:00
Hannah Wolfe
e25f1df0ae
Added card-asset config with sensible default
- This comment removes the block on themes controlling card assets via config
- It also changes the default behaviour from "false" config (doing nothing) to excluding bookmark and gallery card assets
- This is essentially the same thing, as only bookmark and gallery card assets exist at the moment, but it's being done because it makes this feature future-proof for all theme developers.
- As we add new cards, all themes will automatically get the assets to make them work
- As theme developers want to, they can create their own custom assets and disble assets for any cards they support by adding them to the exclude list
- They can also remove any custom code they currently have to support bookmark and gallery cards, and set card_assets: true in package.json to use the defaults instead
2021-11-05 12:20:02 +00:00
Hannah Wolfe
d9bdc444a3
Ensured nonexistant public files fallback to 404
- If we register the serve public file middleware for a file that doesn't exist, this will currently throw an ENOENT error
- Instead, we want to fall back to a standard 404 so that this behaves normally
- This will be useful for the card asset service, where the cards.min.css and cards.min.js files may or may not exist
2021-11-05 09:13:23 +00:00
Naz
142eff22ee Fixed thumbnail file name
refs https://github.com/TryGhost/Toolbox/issues/95

- The uploaded media thumbnail name should have a "_thumb" postfix to be able to distinguish thumbnails from other files. This can be handy if we decide to store them in a different location in the future.
2021-11-04 19:03:45 +04:00
Rishabh Garg
3b90b1f335
Moved launchComplete user setting as global editor setting (#13703)
refs https://github.com/TryGhost/Team/issues/807

The launch wizard completed flag was previously stored at per user level in accessibility column of user table, so an administrator still got the option to complete the launch wizard even if the owner had completed it previously, which is not expected pattern. This change moves the launch complete flag for Admin to common settings from per user level so a site only needs to complete the launch wizard once irrespective of which user completes it

- adds new `editor_is_launch_complete` setting to track if a site launch steps are completed in Admin
- adds new migration util to easily allow adding new setting 
- adds migration to introduce new `editor_is_launch_complete` setting
- adds migration to update launch complete flag for a site if any of the users have already completed the launch steps
2021-11-04 18:03:51 +05:30
Hannah Wolfe
fdf38ba8c6
Initial card asset service implementation
- Requires the new @tryghost/minifier package
- Adds a new service that will handle taking config from the theme and optionally including assets for Koenig editor cards
- It supports both css and js as cards may need one or both
- For any given config, the tool can find the matching files to include and concat and minify them into one file per type
- Currently has an override in place so that this is not yet customisable in the theme - will remove this override when we're ready for the feature
2021-11-04 11:34:40 +00:00
Naz
df5c87fae3 🐛 Fixed a 500 error when uploading invalid routes.yaml
closes https://github.com/TryGhost/Toolbox/issues/111

- Just like with invalid JSON redirects files we should return a BadRequestError instead of throwing a generic 500 when the redirects.yaml file fails parsing
2021-11-04 11:52:52 +04:00
Naz
091240db48 Added thumbnail upload support to Media API
refs https://github.com/TryGhost/Toolbox/issues/95

- Each media file quires a thumbnail and these changes provide a capability to upload them along with media files.
- The thumbnail file is always required and has to be the format of already supported image formats
- The thumbnail should be uploaded as a part of "thumbnail" attachment in the request
- The regression tests added with this changeset will be claened up and moved to unit-tests (this is a dirty-but-working version!)
- The thumbnail always gets a name of the uploaded media file and keeps it's own extension.
- The thumbnails is accessible under the url present in the "thumbnail_url" reponse field
2021-11-04 10:23:29 +04:00
Thibaut Patel
c32cc3e48b 🐛 Fixed broken assets for theme/design preview
refs https://github.com/TryGhost/Team/issues/1190

- The assets were broken in Admin when the frontend and admin urls were different
- Fixed the issue by changing the `asset` helper to output absolute URLs when the frontend/admin urls are differents
2021-11-03 11:20:04 +01:00
Naz
0ccf31cdb5 Fixed error message when booting with no redirects
refs 91efa4605c

- When the instance is booted without any redirects files configured it's not supposed to error but rather default to an "empty" [] redirects configuration.
- Ideally the logic shoudl not contain try/catch block at all and fail as soon as there's any error during the initialization. This wasn't changed at this time due to possible break of existing Ghost instances
2021-11-03 13:50:24 +04:00
Naz
c080f4b77d Fixed redirects integration tests
refs refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- The tests needed to have a clean state with empty redirects file, which was previously ensured through "configUtils". Because configUtils don't play ball with the class initialization pattern this approach was chosen
- It's an end-to-end test with lots of logic and pobably would be enough to run against single API endpoint. Leaving it as is and to be improved in the future
2021-11-03 07:41:55 +13:00
Naz
a9952b2437 Rewrote validation regression tests to be unit tests
refs refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- These regression tests are slow and should have been unit tests to start with
2021-11-03 07:41:55 +13:00
Naz
d101ef5293 Rewrote validation regression tests to be unit tests
refs refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- These regression tests are slow and should have been unit tests to start with
2021-11-03 07:41:55 +13:00
Naz
f4e725a7ef Removed redirects regression tests in favor of unit test
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- Removed "download" regression tests as those cases were ported over to much faster unit tests
2021-11-03 07:41:55 +13:00
Naz
1c4dea00b9 Removed redirects regression tests in favor of unit test
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- The regression test should not be testing edge cases like this and it's far more flexible and performant to test the service on the unit test level
2021-11-03 07:41:55 +13:00
Naz
c3edd4b3d4 Fixed redirects regression tests
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- The problem this change is addressing is inability to override config values once the code is extracted into a class+DI pattern
- The work around is restarting the instance with the configuration testing expected behavior - in this case missing or existing types of redirects files
2021-11-03 07:41:55 +13:00
Fabien O'Carroll
91efa4605c Used DynamicRedirectManager for Custom Redirects
refs https://github.com/TryGhost/Members/commit/9e59f5a9

Since we have a DynamicRedirectManager for handling adding/removing
redirects at runtime, we no longer need the custom-redirects middleware.
The redirects service does however need an init method now to add the
custom redirects at Ghost boot, so it's been refactored into our Class &
DI pattern.
2021-11-03 07:41:55 +13:00
Naz
7eb7e00634 Added test coverage for not supported media type
refs https://github.com/TryGhost/Toolbox/issues/95

- Only supported media types should be accepted by `/media/` enpoint
2021-11-03 00:33:28 +13:00
Naz
4a551661d9 Implemented '/media/upload' API endpoint
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- This is an experimental implementation of video file upload support
- Also the output serializer skipped use of url utils in favor of inline implementatoin - this should almost certainly be it's own package
2021-11-03 00:33:28 +13:00
Naz
4907b7bf1e Added media fixtures for video files
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- Example source files downloaded from https://filesamples.com/
- These fixtures will be used in media endpoint tests
- They had to go in a separate commit as git doesn't like to batch up big files
2021-11-03 00:33:28 +13:00
Naz
5242566252 Added local media storage adapter
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- This is an experimental implementation of video file upload support (audio is yet to follow)
- The storage adapter still needs more thinking as it's almost the same as the "LocalStorgeAdapter" that stores images.
- Also the output serializer skipped use of url utils in favor of inline implementatoin - this should almost certainly be it's own package
2021-11-03 00:33:28 +13:00
Rishabh
1a9705b824 🐛 Fixed error in setting page access to tiers
closes https://github.com/TryGhost/Ghost/issues/13704
closes https://github.com/TryGhost/Team/issues/1186

- updates page serializer to handle new `visibility_filter` property for filtering access on specific tier
- this change was already added for `posts` but was missed on `pages`, so parsing filter on `visibility` filter was failing
2021-11-02 13:36:32 +05:30
Fabien 'egg' O'Carroll
b36d0cc1c4
🐛 Fixed idempotentcy of addPermissionToRole util (#13685)
refs https://github.com/TryGhost/Team/issues/1178

The "up" migration that this util generates correctly throws if the
pre-requisite data cannot be found in the database. The "down" migration
however was incorrectly mirroring this behaviour of throwing - which
meant that it wasn't idempotent, as it does not require a permission or
role to existing if it wants to move relations between them.
2021-11-01 09:27:50 +00:00
Thibaut Patel
6e0bd7e7b5 Added fallbacks when the site title is undefined
refs https://github.com/TryGhost/Team/issues/1180

- An undefined site title was causing the `null` string to show in the html title tag on tag and author pages
2021-10-27 12:18:57 +02:00
Hannah Wolfe
b736a32eb9
Fixed mock-express style tests
- custom theme settings have to be initialised before the theme service
2021-10-25 09:56:54 +01:00
Kevin Ansfield
a485509a2f
🐛 Fixed GA labs flags not appearing enabled in settings API (#13681)
no issue

The way GA flags were introduced means that they stop existing in the `'labs'` setting in the db and are instead forced to always return `true` when checking the flag in the labs service. However, Admin which uses the flags fetches them via the `/settings/` API endpoint which was only returning the raw labs setting db value meaning GA flags appeared to be disabled unless the flag had previously been enabled and no settings save had occured.

- updated the settings bread service to replace the labs setting value with the JSON stringified output of `labs.getAll()` which is the ultimate source-of-truth for a feature being enabled/disabled
  - extracted `browse()` behaviour to an internal `_formatBrowse()` method so we can apply the same filtering/modification for output of `browse()` and `edit()`

Co-authored-by: Fabien O'Carroll <fabien@allou.is>
2021-10-22 19:59:13 +01:00
Fabien O'Carroll
f3bb6b43a5 Added Offers feature to Ghost
refs https://github.com/TryGhost/Team/issues/1115

This allows users to create Offers for Tier/Cadence pairs in order to
provide discounted subscriptions to Members! We have support for
percentage based discounts & fixed price discounts, either for the first
payment, all payments, or a number of monthly payments.

Offers also have a code, which can be used as an easy way to share them,
as visiting https://site.com/offer-code will automatically open Portal
with the Offer prepopulated.
2021-10-22 17:55:34 +02:00
Kevin Ansfield
a6982d5606
Added ability for themes to define custom settings (#13661)
closes https://github.com/TryGhost/Team/issues/1164

Themes can now define custom settings via their `package.json` file, and use them in templates via `@custom.{setting}`. Values for custom settings can be changed by site owners through a redesigned "Design settings" area in the admin interface.

Full announcement, documentation, and examples will be made available soon.

Co-authored-by:
- Sanne de Vries (@sanne-san)
- Thibaut Patel (@tpatel)
2021-10-22 15:02:16 +01:00