System Information
- Strapi Version: 3.4.3
- Operating System: ubuntu
- Database: postgres
- Node Version: 14
- NPM Version: 6.14
Integration Tests - Simulating Requests via Strapi Admin GUI
I have a cache middleware which busts the cache when a POST/PUT request is made via /content-manager/collection-types/:scope. I would now like to write an integration test.
How can I use the global Strapi object or send a request to the Strapi backend endpoint to simulate a user action in the Strapi Admin GUI? My intention is to simulate a user action in the Strapi Admin GUI.
I have tried the following…
const result = await strapi.plugins['content-manager'].controllers['collection-types'].create({
state: { user: 2, userAbility: { can: () => true, cannot: () => false } },
params: { model: 'application::ad.ad' },
request: { body: { description: 'test' } },
});
but it fails…
1) [Redis Cache]: Integration Tests
REST - Cache Bust via Admin:
TypeError: n.possibleRulesFor is not a function
at n.permittedFieldsOf (node_modules/@casl/ability/src/extra.ts:101:32)
at Object.sanitize (node_modules/strapi-admin/services/permission/permissions-manager/index.js:52:29)
at sanitizeInput (node_modules/strapi-plugin-content-manager/services/permission-checker.js:38:31)
at sanitizeCreateInput (node_modules/strapi-plugin-content-manager/services/permission-checker.js:45:39)
at .../backend/node_modules/lodash/lodash.min.js:56:306
at Object.create (node_modules/strapi-plugin-content-manager/controllers/collection-types.js:82:61)
at _callee7$ (test/integration/cache/cache.test.js:115:92)
at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:293:22)
at Generator.next (node_modules/regenerator-runtime/runtime.js:118:21)
at asyncGeneratorStep (test/integration/cache/cache.test.js:3:103)
at _next (test/integration/cache/cache.test.js:5:194)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Question
Has someone done something like this? And/or is there a better way to do it? For example, is there a function to create a proper userAbility object instead of this mock version.