Commit Graph

361 Commits

Author SHA1 Message Date
Kevin Ansfield
96ec60e393
🐛 Fixed "Create Post" action error in Zapier when assigning new tags (#13972)
closes https://github.com/TryGhost/Zapier/issues/56

- fixes tag creation when creating posts with `tags: [{slug: 'new'}]` which should be supported
  - assigning tags with only `{slug: 'new'}` was triggering our validation for the required `name` property then bubbling up to the `bookshelf-relations` library resulting in a 500 error
  - the fix applied here is to set the `name` field to the same as the `slug` field if a name is not provided
2022-01-14 13:37:20 +00:00
Naz
f4ad3b23ba Removed need for 'Origin' header in test suites
refs https://github.com/TryGhost/Toolbox/issues/129

- The "Origin" header is require in Admin API requests so it makes sense to bake it into a default request made by most tests. Reduces unnecesary fluf around test request setup and removes a "config" dependency in each tests suite using the "e2e framework"
2021-12-10 11:05:37 +04:00
Naz
5a150cc3b6 Removed duplicate snapshot initialization code
refs https://github.com/TryGhost/Toolbox/issues/158

- Allows for much smaller amount of code to configure a test to work with chai-jest-snapshots. They now work automatically for all regression tests and could be enabled for other suites by adding the "--require=./test/utils/snapshots.js" parameter in respective test:* package script
- Regenerated snapshot for authentication test as the naming structure
changed a little with the snapshot metadata being taken on a higher
level in the test (uses the suite name instead of a specific describe it
used to be called from)
2021-12-10 06:37:31 +13:00
Naz
309e14b8c9 Moved email stubbing logic into e2e-framework utils
refs https://github.com/TryGhost/Toolbox/issues/158

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

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

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

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

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

- Provides an example of how to use the e2e framework.
2021-12-09 22:20:54 +13:00
Naz
6762e2a60d Started a greenfield e2e test framework
refs https://github.com/TryGhost/Toolbox/issues/129

- Having a fresh module should allow building new testing utility concepts from the ground up without being tied by the mystery baggage of the legacy localUtils/testUtils
- The outline of the concepts the framework will be handling is in the commont on the top of the e2e-framework file
2021-12-09 22:20:54 +13:00
Naz
a18fa18ff3 Fixed authentication test suites
refs https://github.com/TryGhost/Toolbox/issues/152

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

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

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

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

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