Commit Graph

1167 Commits

Author SHA1 Message Date
Hannah Wolfe
130ffb4d63
Updated snippets e2e tests to use new framework
- Snippets are are one of the most recently implemented full e2e features
- https://github.com/TryGhost/Ghost/commit/13f653a12 updated the serialier pattern
- This updates the tests so _everything_ is shiny and new
2022-03-29 15:51:46 +01:00
Hannah Wolfe
f7ad32e76b
Removed unnecessary snippets serializer
refs: https://github.com/TryGhost/Toolbox/issues/245

- The default behaviour of a serializer is to call a mapper for each object
- Instead of all the boilerplate code we had in the snippets serializer, all we need is a single mapper function
- Added tests for the mapper function as well
2022-03-29 15:51:45 +01:00
Thibaut Patel
f096e29922 Added the newsletters table
refs https://github.com/TryGhost/Team/issues/1433

- The `default` property stores whether a newsletter is set as default by the admin
- The `status` property stores whether a newsletter is archived or not
- The `recipient_filter` property is only storing whether a newsletter is "paid-only" or not for now, although it can be expanded to more specific filters in the future
- The `subscribe_on_signup` property stores whether a new member should be automatically signed up to the newsletter
- The `sort_order` property enables displaying the newsletter list in an order chosen by the admins
2022-03-29 15:23:26 +02:00
Hannah Wolfe
22b6f1af99 Improved behaviour of default and all handlers
refs: https://github.com/TryGhost/Toolbox/issues/245

- .all methods are fallback serializers not to be run as well as a custom serializer
- The default serializer is also a fallback
- The "All" file with before and after are global hooks that _always_ get run as well as other serializers
- There's a lot of room for further improvement here especially with naming but this logic makes more sense
  for the usecases AND doesn't affect v2 & v3 etc. We can do another pass after 5.0
2022-03-29 13:44:21 +01:00
Hannah Wolfe
9f3b6f1818
Added missing e2e emails API browse & retry tests
refs: https://github.com/TryGhost/Team/issues/1446

- changed Emails API tests to use the new e2e test framework
- Added missing tests for browse and retry endpoints
2022-03-28 17:32:58 +01:00
Hannah Wolfe
ccef6dc44e
Added event mocking to e2e framework
- Allows mocking lib/common/events - stubs event.emit
- Means we can check that events fired, but their sideeffects won't happen, useful for things like bulk email
- I also reorganised the mock manager file to group related functions together
2022-03-28 17:32:57 +01:00
Hannah Wolfe
15da07f324
Added missing e2e mail API retry test
refs: https://github.com/TryGhost/Team/issues/1446

- changed mail API  tests to use the new e2e test framework
- added the missing retry test - which has the wrong response format :(

mail
2022-03-28 17:32:57 +01:00
Daniel Lockyer
32e2d15880
Split apart DB init queries in tests
refs https://github.com/TryGhost/Toolbox/issues/213

- `better-sqlite3` doesn't like multiple queries in the same statement
  so we can make the change here to split them up ahead of the switch
2022-03-28 16:17:17 +01:00
Hannah Wolfe
a31069d49d
Removed unnecessary use of rewire
refs: https://github.com/TryGhost/Ghost/commit/e68cb8b31

- I found that some of the places we use rewire are totally unnecessary
- Rewire seems to mess with coverage sometimes
- It's also a code smell in general so I've ripped it out where possible
2022-03-24 19:32:06 +00: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
0ef5a5c97a
Fixed members connect endpoint returning JSON
refs: https://github.com/TryGhost/Toolbox/issues/245
refs: https://github.com/TryGhost/Team/issues/1360

- As a result of my changes in https://github.com/TryGhost/Ghost/commit/3bd4d098 the members connect endpoint had started returning JSON
- This is because the members connect endpoint relied on the old default behaviour of the serializer being to return no response, whereas now it does our default JSON response format
- I had written a tool to iterate over all endpoints and ensure that they all had explicit serializers before changing the default behaviour, but it missed this endpoint due to the snake case naming
- I have double checked and this was the only missed endpoint, the only other one was member_signin_urls.permissions but that was not a true endpoint and was removed in https://github.com/TryGhost/Ghost/commit/202696382
- Note: the snapshot file for this test was generated from running the test against https://github.com/TryGhost/Ghost/commit/e6b92aed9 - one commit before I added the new default behaviour.
  - Without the new serializer this test fails on main
  - With the new serialzier, this test passes again, showing the response format has gone back to what we expect
2022-03-24 17:09:23 +00:00
Hannah Wolfe
6976a3a9f2
Added labels test for empty browse response
- Added a simple test to prove the response is in the correct format when there is no results
2022-03-24 12:52:47 +00:00
Simon Backx
a7566c8503
Added e2e tests for offers API (#14335)
refs https://github.com/TryGhost/Team/issues/1429

Includes tests for all endpoints of the offers API
2022-03-24 13:41:48 +01:00
Naz
7d03194e55 Added detection of "ghost-api" use in theme config
refs https://github.com/TryGhost/Toolbox/issues/241

- The `engines.ghost-api` property has been deprecated and the support for it will be dropped in Ghost v5 due to versionless nature of the Content API.
- When uploading a new theme or activating existing one that uses ghost-api in it's config a warning will be shown to the user
2022-03-24 15:27:40 +13:00
Hannah Wolfe
9db1694647 Removed unnecessary tags serializer
refs: https://github.com/TryGhost/Toolbox/issues/245

- we don't need this serializer because the default serializer will call the tags mapper
- for now I've changed, rather than removed the tag serializer test as this shows default works the same!
2022-03-23 13:23:23 +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
e68cb8b314
Improved settings cache unit tests
- settings cache was appearing as untested because we use rewire!
- rewire was totally unnecessary in this case, so I removed it
- updated to 100% test coverage whilst there, including removing one unreachable branch
- commented some undesirable behaviour I found whilst trying to reach all branches
- I don't want to change the behaviour to return false correctly without having a reason beyond improving coverage
2022-03-23 11:37:52 +00:00
Hannah Wolfe
3bd4d0989a Added default serializer + handling
refs: https://github.com/TryGhost/Toolbox/issues/245

- Added a serializer called default to the canary API
  - Ideally, this would be part of the shared framework, but this would change v2/v3 and we're about to get rid of them
  - Therefore, we change just canary for now, and we can refactor again later.
- Added wiring to handler that uses the default serializer, if there is a default, and isn't an explicit serializer for the endpoint
- Removed the invites serializer, so that one endpoint now uses the default

Note: previous commits have added explicit serializers to every endpoint, this is the first step towards paring
that back so that we have less serializers overall, not more!
2022-03-22 13:52:32 +00:00
Hannah Wolfe
3919d31838 Added serializer for missing settings endpoints
refs: https://github.com/TryGhost/Toolbox/issues/245

- Upload, updateMembersEmail, validateMembersEmailUpdate & disconnectStripeConnectIntegration were all missing serializers
- Upload is an as-is response, same as download
- updateMembersEmail, validateMembersEmailUpdate & disconnectStripeConnectIntegration are all passthroughs with no response
- With the upcoming refactor we want to have all the serializers defined explicitly
- This will allow us to change the default behaviour
- Updated the file based tests to prove the body doesn't change
- Tests were added to cover updateMembersEmail, validateMembersEmailUpdate & disconnectStripeConnectIntegration in 68c1bc0285
2022-03-22 13:52:32 +00:00
Hannah Wolfe
7e6a7cb98c Added serializer for email_preview.sendTestEmail
refs: https://github.com/TryGhost/Toolbox/issues/245

- sendTestEmail was missing a serializer because it's deliberately a passthrough
- With the upcoming refactor we want to have all the serializers defined explicitly
- This will allow us to change the default behaviour
- Updated the tests to prove the body doesn't change
2022-03-22 13:52:32 +00:00
Hannah Wolfe
84500be0e2 Added serializer for themes.destroy
refs: https://github.com/TryGhost/Toolbox/issues/245

- The destroy endpoint was missing a serializer
- Instead of adding one, I've refactored to use an all method that's a passthrough
- Updated the tests to use the same pattern as others to make it clearer this is tested
2022-03-22 13:52:32 +00:00
Hannah Wolfe
ac3f18b251 Added serializer for snippets.destroy
refs: https://github.com/TryGhost/Toolbox/issues/245

- The destroy endpoint was missing a serializer
- As this serializer uses the same createSerializer pattern as members, I've copied the passthrough from members into here
- This ensures the behaviour will stay the same when the default behaviour changes
- Updated the tests to prove the body doesn't change
2022-03-22 13:52:32 +00:00
Hannah Wolfe
c89a01b031 Added serializer for integrations.destroy
refs: https://github.com/TryGhost/Toolbox/issues/245

- The destroy endpoint was missing a serializer
- Instead of adding one, we've refactored to use the standard structure for this serializer
- Updated the tests to prove the body doesn't change
2022-03-22 13:52:32 +00:00
Hannah Wolfe
7433378e6a Added serializer for redirects.upload
refs:  https://github.com/TryGhost/Toolbox/issues/245

- There was only a serializer in place for redirects.download.
- Upload was falling through, which means nothing happens by default atm
- We want to change this default, so I'm making sure all our routes have serializers declared and tests
- Updated the tests and checked the behaviour was the same before and after:
  - We can't use our new framework here yet because it doesn't support uploads or downloads
  - Instead, just add simple matching for the body of the responses
2022-03-22 13:52:32 +00:00
Naz
3c9531452c Reverted "Added detection of "ghost-api" use in theme config"
This reverts commit 4c19f38c74.
2022-03-22 16:18:17 +08:00
Naz
4c19f38c74 Added detection of "ghost-api" use in theme config
refs https://github.com/TryGhost/Toolbox/issues/241

- The `engines.ghost-api` property has been deprecated and the support for it will be dropped in Ghost v5 due to versionless nature of the Content API.
- When uploading a new theme or activating existing one that uses ghost-api in it's config a warning will be shown to the user
2022-03-22 14:05:34 +08:00
Simon Backx
028cf7becc Added dashboardV5 feature flag 2022-03-21 16:56:34 +01:00
Thibaut Patel
6e9bc81d6d Fixed the tests from the previous commit
refs 2324b29b2a

- Updated the settings snapshot
2022-03-21 16:28:26 +01: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
Hannah Wolfe
68c1bc0285 Added missing settings endpoint tests
- Added a test for each of the 3 missing endpoints
- This is so that we can be sure future refactors won't break these endpoints
2022-03-19 16:06:07 +00:00
Hannah Wolfe
c66eeb5879 Updated settings to use new test framework
- split out the two tests that use files, as the new framework doesn't support this yet
- convert the 3 existing tests for the settings endpoint to use the new framework
- introduced a new pattern of using a function to generate a matching array, so that we can do extra stuff
- in this case, just one of the items needed a matcher for the value, which results in slightly weird code
- wrapping in a function gives us somewhere to do this and leave a comment
2022-03-19 16:06:07 +00:00
Hannah Wolfe
c11187d770 Updated members tests to use defined matcher
- some tests were inconsistently using copy-pasted matchers
- instead, we should define them once and use them everywere
- this keeps the tests easy to read and maintain
2022-03-19 16:06:07 +00:00
Kevin Ansfield
95c919852b
Fixed missing product name in API response when editing creating/editing subscriptions (#14339)
refs https://github.com/TryGhost/Team/issues/1141

- switched to the same member fetch method as used in `GET /member/:id/` so there's consistent data available when rendering the API responses
2022-03-18 16:06:38 +00:00
Hannah Wolfe
2cf7e00493 Added tests for session API
- this API has never had proper tests!
- using the new framework this was pretty easy :)
2022-03-18 13:13:16 +00:00
Hannah Wolfe
911ce5f92d Cleaned up db-utils and added jsdocs
- Attempted to make it clearer what the db utils do and what each one is for
- Clearly marked the old clearData & initData as deprecated, we don't want to mix db and url service resets
2022-03-17 17:33:11 +00:00
Hannah Wolfe
11a792f7df Wrapped test teardown in a fallback
- The fast truncateAll method can fail
- If it does, use knex-migrate to do a safe reset of the DB instead
- This is being done to try to make test runs more reliable in the face of database errors
2022-03-17 17:33:11 +00:00
Hannah Wolfe
b90e367563 Fixed error handling on db truncate in tests
- if the database does not exist, ignore the error
   - tables that don't exist don't need truncating
   - instead wait until the next thing calls init, that will cause a fresh db to be created in the correct state
- inside of reset, if the truncate fails then do a full reset instead
2022-03-17 17:33:11 +00:00
Hannah Wolfe
83ad79308b Updated tests to use DatabaseInfo
- some code in tests were still using various unreliable methods to determine the database in use
- DatabaseInfo is the correct method to check if the db is mysql or sqlite
- Exposed DatabaseInfo via our test db-utils to make this easier
2022-03-17 17:33:11 +00:00
Matt Hanley
340f64c2df Updated test snapshot for tiers e2e tests
- 18b59d2c01 renamed a test which invalidated the old snapshot
- the new snapshot wasn't committed
2022-03-17 14:03:12 +00:00
Kevin Ansfield
0cc147ae2d 🐛 Fixed member "last seen at" data not being returned in the API
refs c4470ff732

- labs flag was removed under the false assumption it was a client-side only flag but the `last_seen_at` property in API responses was also gated meaning the member details screen showed "Not seen yet" and the members list did not show the last seen date of all members when filtering
2022-03-17 10:58:07 +00:00
Fabien 'egg' O'Carroll
9ff8d7f910
🐛 Fixed post access in the get helper (#14282)
refs https://github.com/TryGhost/Team/issues/1367

Because we are passing through a different member object as the context
in the get helper, the content gating was not working correctly, as the
member was missing a status property, this adds the property which fixes
content gating.

- Added extra tests for get helper {{access}} property
- Added extra test for {{access}} property in next_post helper
- In the future we might want to update the tests so they test the whole request -> HBS context flow. Currently the has context is still stubbed manually.
2022-03-17 11:14:29 +01:00
Hannah Wolfe
2cc2d114f4
Revert "Added global setup to reset DB before test run"
This reverts commit d50fb7c922.
2022-03-16 21:10:49 +00:00
Hannah Wolfe
d50fb7c922
Added global setup to reset DB before test run
- We've been seeing weird errors with tables not existing when running tests locally
- This appears to happen after an error causes the tests to abort
- This change includes two fixes:
1. we triggers a full DB reset just before the entire test suite runs
 - this is done by wrapping the override file for tests that use a db, and supplying a mochaGlobalSetup hook
2. catch errors when attempting to do a fast truncation-based reset & init, and do a full reset & init instead

- These two changes should ensure the DB is always in the state we expect when running a new test suite
2022-03-16 20:56:17 +00:00
Rishabh Garg
18b59d2c01
Removed archived tiers from content api (#14329)
closes https://github.com/TryGhost/Team/issues/1426

When fetching tiers using the content API, we incorrectly returned all tiers including archived ones unless the active:true filter is passed. Correct behaviour is to always hide archived tiers, so this filter should not be required.

- forces `active:true` filter for tiers content api browse
- updates test to check for archived test removal in tiers content api
2022-03-16 22:02:42 +05:30
Hannah Wolfe
1a6a283a50
Fixed bad setup call in settings integration test
- the setup() function returns a function that's expected to be called as a mocha hook
- wrapping this in a function means it doesn't get called properly
- therefore the db setup was never being called for this test
2022-03-16 14:03:02 +00:00
Hannah Wolfe
4dd2ebc78b
Fixed local-only e2e test failure
fixes: https://github.com/TryGhost/Team/issues/1424

- This moves the require of the members service after Ghost has been booted normally.
- This gives the tests time to properly setup temporary folders before the paths get used.
- In turn this prevents issues in the legacy-members tests, which were affected by the Member Service being called too early in this test.
2022-03-16 12:53:58 +00:00
Hannah Wolfe
70d15e077b
Refactored mapper into individual files (#14328)
refs: https://github.com/TryGhost/Toolbox/issues/245

- Ghost's API framework has a mixed up concept of what a serializer is. Mappers are true serializers! What we call serializers are little more than a small formatting step.
- This PR splits mappers into individual files and uses the endpoint's docname as the mapper name. This will help us to automate the calling of a mapper for an endpoint later.
- This is one tiny step in reworking the framework to need less code to make it work, and to have clearer concepts for how to do things.
2022-03-16 12:44:11 +00:00
Rishabh Garg
f9aa18a534
Enabled Admin integration for tiers and offers API (#14325)
As multiple tiers is now GA, we want to allow devs to be able to work with Tiers and offers via content/Admin API. This change -

- updates fixtures to add permissions to admin integration role for new sites
- adds migration to update existing sites to have correct permissions for role
- whitelists add/edit/read/browse on tiers and offers API for integrations
2022-03-16 16:46:26 +05:30
Naz
cbba5471a2 Renamed versioned API URL variable
refs https://github.com/TryGhost/Toolbox/issues/169

- Improved code readability, otherwise it could be confusing what the default API URL means
2022-03-14 21:22:54 +13:00