Commit Graph

430 Commits

Author SHA1 Message Date
Naz
275107d423 Added test coverage for author reassignment
closes https://github.com/TryGhost/Toolbox/issues/268

- Adds more coverage to the author reassignment method as it hasn't been covered much. It should put a good base to expand upon in case a bug pops up
2022-05-03 14:57:35 +08:00
Naz
4edec18289
Fixed lint error 2022-04-28 15:37:14 +01:00
Naz
ce19cf80bf
Added better coverage for author reassignment
refs https://github.com/TryGhost/Toolbox/issues/268

 - The test didn't check if the posts were successfully reasigned, so have added that part of logic
2022-04-28 15:37:13 +01:00
Naz
b123a9bb77
Refactored multiauthor posts suite to async/await
refs https://github.com/TryGhost/Toolbox/issues/268

 - I'm about to rewrite it, so made the test suite slightly more readable to keep track of changes easier
2022-04-28 15:37:13 +01:00
Naz
5b43b4f40d
Fixed failing reassignByAuthor test
refs https://github.com/TryGhost/Toolbox/issues/268

 - After the logic change the number of posts no longer decreases - reassignment does not delete posts
 - In a follow up commit will add a more sophisticated check for actual reassignment
2022-04-28 15:37:13 +01:00
Daniel Lockyer
68cffa62ae
Renamed email-preview file to email-previews
refs https://github.com/TryGhost/Toolbox/issues/308

- I recently pluralised the API endpoint but never made the changes to
  the controller file and everywhere else it's needed
- this commit cleans up that inconsistency so it should be clearer
2022-04-28 15:37:12 +01:00
Daniel Lockyer
0f5c22a38d
Cleaned up mention of subscribers in test folder
refs https://github.com/TryGhost/Toolbox/issues/308

- we had a few mentions of `subscribers` in the test suite data generator
  but this shouldn't be used any more because it's an ancienttttt concept
- removing this for v5 as it helps to clean the codebase
2022-04-28 15:37:12 +01:00
Daniel Lockyer
ea3c927d94
Renamed reset_all_passwords Authentication API endpoint to /global_password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- our API has a pattern of using nouns and not verbs for the endpoint
  names, so this changes the endpoint for v5
2022-04-28 15:37:11 +01:00
Daniel Lockyer
cfa2f0e102
Changed /authentication/reset_all_passwords to return 204 response code
refs https://github.com/TryGhost/Toolbox/issues/308

- this endpoint has no body to return but it was initially implemented
  as returning a 200 which we couldn't change until 5.0
- this changes it to a 204, removes the serializer and updates tests to
  take this into account
2022-04-28 15:37:11 +01:00
Daniel Lockyer
379f64428e
Renamed passwordreset body object to password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- I've just renamed the `/authentication/passwordreset` API endpoint to
  `/authentication/password_reset` and noticed the body object is also
  badly named
- this clears that up in code and tests
2022-04-28 15:37:11 +01:00
Daniel Lockyer
c4f3d44baa
Renamed /passwordreset Authentication API endpoint to /password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- we have the pattern of splitting words in API endpoints with an
  underscore but this was an exception we want to clean up in v5
2022-04-28 15:37:11 +01:00
Thibaut Patel
7422f3e64d Moved to using newsletter design settings in email serializer (#14562)
refs https://github.com/TryGhost/Team/issues/1550

- Switched to using the newsletter design settings over the global settings
- Made the `newsletter_id` property available in the Admin API Post resource
- Added the `showHeaderName` variable that can be used in the post html template
2022-04-26 12:31:34 +01:00
Thibaut Patel
ed29c7addf Filtered member email recipients based on the newsletter subscriptions (#14489)
refs https://github.com/TryGhost/Team/issues/1524

- We need to fetch the post newsletter to grab the slug as it's needed for the member NQL filter.
- We can then use the newsletter slug and append it in the existing member NQL filter.
- Removed `subscribed:true` when an email is sent to a newsletter and replaced it with the newsletter id
- Added `status:-free` when an email is sent to a newsletter with `visibility` set to `paid`
- Added tests what happens when you publish without newsletter_id
- Added tests what happens when you publish with newsletter_id

Co-authored-by: Simon Backx <simon@ghost.org>
2022-04-26 12:31:34 +01:00
Hannah Wolfe
9da57fa6bb Updated test fixtures for multiple newsletters
- Updated the member fixtures to have 6 subscribed and 2 unsubscribed members
- Added an inactive newsletter
- Updated newsletter-member relations to reflect the 6 subscribed and 2 unsubscribed, but with different cases:
   - 3 subscribed to default
   - 1 subscribed to secondary only
   - 1 subscribed to default + secondary
   - 1 subscribed to secondary + inactive
   - 1 subscribed to inactive only (i.e. not subscribed)
   - 1 not subscribed at all

- With these changes, I needed to update the members snap as 2 members appear as subscribed:false in many tests
- I also needed to update some posts regression tests, as 2 less members get emailed in 2 tests
2022-04-26 12:31:34 +01:00
Naz
1ecb837981 Added version_notifications key to settings table
refs https://github.com/TryGhost/Toolbox/issues/292

- When version missmatch handling is done in Ghost we need to store the 'Accept-Version' header values that have been already processed in the past (to avoid sending notifications about the same mismatch multiple times)
- The `version_notifications` will be storing an array with handled versions like so: `['v3.44', 'v4.23', 'v4.39']`.
- The emailing logic and processing is slightly similar to how "notification" key is handled, that's why I've placed the definition of this new key close by.
2022-04-21 20:34:19 +08:00
Rishabh Garg
1362750640
Updated newsletter fixtures to remove nullable sender name (#14479)
refs https://github.com/TryGhost/Team/issues/1513

Since `sender_name` for newsletter is now nullable field, this change removes hardcoded `sender_name` from fixtures.
2022-04-14 23:45:59 +05:30
Rishabh Garg
95670eed52
Handled default newsletter fixtures setup (#14459)
closes https://github.com/TryGhost/Team/issues/1491

With multiple newsletters feature, a site should always have at-least one newsletter by default. Also, as with the default product, the default newsletter also needs to be renamed to the site title during the setup flow.

- adds default newsletter to main and test fixtures
- updates setup flow to rename newsletter name and sender name to site title
- updates model to extend default value for fields
- updates test
2022-04-12 19:44:21 +05:30
Hannah Wolfe
c222d1f64e
Added expectEmptyBody assertions to e2e framework
- Updated express-test to latest version with new expectEmptyBody assertion
- Updated all the tests that used matchBodySnapshot for an empty body to use expectEmptyBody instead
- Updated all the snapshots that were affected manually, and verified running the tests works as expected
2022-03-31 18:56:05 +01:00
Hannah Wolfe
45de9b0efc
Fixed filename casing in canary API
refs: 0ef5a5c97a

- As per the previous commit, our mixed filename casing inadvertently resulted in a bug
- The casing in the codebase is meant to be kebab-case always, so fixing this everywhere that's relevant to the API whilst there's a good reason
2022-03-24 17:25:53 +00:00
Hannah Wolfe
396dd5f7f9 Removed unnecessary labels mapper & serializer
refs: https://github.com/TryGhost/Toolbox/issues/245

- There's no need for a mapper or serializer as labels uses the default behaviour
- Added a full suite of tests, consolidating from regression and using the new framework to prove nothing is broken
2022-03-23 13:23:23 +00:00
Hannah Wolfe
3784d79682
Added fixture path utility to e2e-framework
- Always want to be able to safely get a fixture path without needing the path util
- Means tests can be moved around more easily
2022-03-21 11:14:54 +00:00
Hannah Wolfe
5f378ca3f6
Removed unused snapshot files
- the tests that used these files have been moved to test/e2e-api
2022-03-19 16:48:59 +00:00
Naz
7becf0a2b2 Aliased canary endpoints to point to non-versioned URLs
refs https://github.com/TryGhost/Toolbox/issues/169

- Before releasing Ghost v5 we would like to move all canary-related URLs to a non-versioned format, which will become a default in v5.
- 'canary' is by definition unstable, so breaking any unprepared client explicitly using the canary is expected
- Removed the aliased /content/ and /admin/ apps from app.js because with updated configuration they become duplicates of 'canary' endpoints
2022-03-14 21:22:54 +13:00
Simon Backx
da9de95b74
🐛 Fixed duplicate tags created when slugs contain spaces (#14277)
refs https://github.com/TryGhost/Team/issues/1284

When you create a new post with a tag slug that contains spaces, those spaces will get replaced by dashes. But instead of reusing an existing tag, a new tag is always created.

- New tag slugs are cleaned up before matching with existing tags in the Post model onSaving method
- Cleaned up multiple loops in onSaving of Post model
- Cleaned up syntax when cleaning up tag slug
- Added tests for slugs with spaces
- Added test for too long tag slug causing duplication
2022-03-10 13:07:00 +01:00
Fabien "egg" O'Carroll
8229f8030e Fixed new sites using "Default Product" Tier name
https://github.com/TryGhost/Team/issues/1289

Since we added the free Tier fixture, this was attempting to fix the
free Tier, rather than the default one.
2022-03-10 11:35:03 +00:00
Naz
6b730cf201 Fixed use of anyDate matcher
refs c5f8853ad9

- The change in referenced commit was introduced by mistake
2022-03-03 12:06:40 +07:00
Thibaut Patel
c5f8853ad9
Ignore casper install on setup (#14218)
refs https://github.com/TryGhost/Team/issues/1362

- Casper is already installed, so the installation from github always fail.
- There is no need to display an error message in that case.

Added regression tests for blog setup with the default theme:
- Check whether there are no notifications after completing the setup
- Also test the setup with the default theme
2022-03-02 18:22:20 +01:00
Naz
b3bf19e9e3 Renamed e2e framework date matchers
refs f48892028d
refs 33da584161

- There was another mather added recently: anyDateWithTimezoneOffset. The naming of date-related matchers was getting long and confusing. Renamed existing date matcher to better reflect what they do and they types of matches they are responsible for, following renames have been done:
- anyShortDate  -> anyISODate
- anyDate  -> anyISODateTime
- anyDateWithTimezoneOffset  -> anyISODateTimeWithTZ
2022-03-01 18:17:13 +07:00
Aileen Nowak
92d9029500 Added accentColor and description parameters to /authentication/setup route
refs https://github.com/TryGhost/Team/issues/1382

- Added two possible new setup values: `accentColor` and `description` to define the brand colour and site description on initial setup
- Updated tests to reflect those changes
- Only the params when passed and fall back to default site description
2022-02-24 12:36:57 -04:00
Thibaut Patel
b10ea7c714 Removed the duplicated members regression tests
no issue
2022-02-17 15:44:48 +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
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
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
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
Hannah Wolfe
c80e68b93a
Updated all members tests to use mockManager
- This part of the framework can be used in isolation
- Using mockManager everywhere makes it more visible how to use it
- Aside: fixed .getAdminAPIAgent not needing a URL in site tests whilst cleaning up
2022-02-10 12:21:05 +00:00
Thibaut Patel
26c6238c3b Released to GA the theme parameter in the /authentication/setup route
refs daeb06e835

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

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

- if we had to combine a large list of params then this would make sense
- we could/should also add a .query() method to our agent
- however, I don't think this is worthwhile/necessary for just 2 params right now :)
2022-02-09 21:14:17 +00:00
Hannah Wolfe
527cb01680 Updated members tests to use snapshot testing
refs: https://github.com/TryGhost/Toolbox/issues/158

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

- Cleans up the different ways that labs could be mocked into a simple helper
2022-02-08 20:31:02 +00:00
Hannah Wolfe
ac85208441
Cleaned up reference tests
refs: https://github.com/TryGhost/Toolbox/issues/158

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

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

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

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

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

This library also has (after some back and forth) path resolution so that snapshots can live in a local __snapshots__ folder
2022-02-08 14:33:19 +00:00
Hannah Wolfe
b2a5bc980e
Abstracted sentEmail assertions as part of mock utils
The idea here is to keep the concept of _what_ we're asserting (that an email was sent)
away from the implementation of how we check that assertion

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

Much more cleanup to come behind the scenes, but the aim is to make the tests as clean as possible
2022-02-07 17:28:53 +00:00
Hannah Wolfe
efdae70cbc
Updated members regression tests to use e2e framework (#14130)
- This is an example refactor to the new framework
 - This does not yet include snapshot testing (coming SOON)
2022-02-07 17:15:55 +00:00
Hannah Wolfe
5210e84b26
Improved e2e-framework API
- encapsulated concerns within individual objects
- this will allow us to refactor these into classes or move them around later
- also makes it clearer how methods like restore relate to other methods
- e.g mocks.restore() restores mocks, whilst fixtureManager.restore() restores the database
2022-02-07 16:09:54 +00:00
Hannah Wolfe
82d2228bca
Added db reset to new e2e framework
- Ensure that the DB is always reset between tests
- We assume that the DB will be torn down and rebuilt between tests
- Without this, previous tests clobber the current tests, and it's not possible to tell when running files in isolation
which makes developing really tricky
2022-02-07 16:09:54 +00:00
Thibaut Patel
daeb06e835 Added a theme parameter to the /authentication/setup route
refs https://github.com/TryGhost/Team/issues/1296

- The `theme` must be a github `org/repo` string
- This uses the internal API instead of the services because the API has extra implementation details not present in the services.
2022-02-07 12:03:40 +01:00
Hannah Wolfe
88d1d1d4a0 Split members importer and members tests
- This is so that we can start refactoring more tests to use our new e2d framework
- That framework doesn't support file uploads yet, so tests with uploads are split out
2022-02-06 18:02:56 +00:00