1- // import type { Core } from '@strapi/strapi';
1+ import type { Core } from '@strapi/strapi' ;
22
33export default {
44 /**
@@ -16,5 +16,118 @@ export default {
1616 * This gives you an opportunity to set up your data model,
1717 * run jobs, or perform some special logic.
1818 */
19- bootstrap ( /* { strapi }: { strapi: Core.Strapi } */ ) { } ,
19+ async bootstrap ( { strapi } : { strapi : Core . Strapi } ) {
20+ // Seed the database with some test data for the integration tests.
21+ if ( process . env . NODE_ENV === 'test' ) {
22+ // Give the public role some permissions to test with
23+ const roles = await strapi
24+ . service ( 'plugin::users-permissions.role' )
25+ . find ( ) ;
26+
27+ const publicId = roles . filter ( ( role ) => role . type === 'public' ) [ 0 ] ?. id ;
28+
29+ if ( publicId ) {
30+ const publicRole = await strapi
31+ . service ( 'plugin::users-permissions.role' )
32+ . findOne ( publicId ) ;
33+
34+ publicRole . permissions [ 'plugin::webtools' ] = {
35+ controllers : {
36+ core : {
37+ router : { enabled : true } ,
38+ } ,
39+ 'url-alias' : {
40+ find : { enabled : true } ,
41+ } ,
42+ } ,
43+ } ;
44+
45+ publicRole . permissions [ 'api::test' ] = {
46+ controllers : {
47+ test : {
48+ find : { enabled : true } ,
49+ } ,
50+ } ,
51+ } ;
52+
53+ publicRole . permissions [ 'api::category' ] = {
54+ controllers : {
55+ category : {
56+ find : { enabled : true } ,
57+ } ,
58+ } ,
59+ } ;
60+
61+ await strapi
62+ . service ( 'plugin::users-permissions.role' )
63+ . updateRole ( publicRole . id , publicRole ) ;
64+ }
65+
66+ await strapi . entityService . create ( 'plugin::webtools.url-pattern' , {
67+ data : {
68+ pattern : '/page/[title]' ,
69+ label : 'Test API pattern' ,
70+ code : 'test_api_pattern' ,
71+ contenttype : 'api::test.test' ,
72+ languages : [ 'en' ] ,
73+ } ,
74+ } ) ;
75+
76+ await strapi . entityService . create ( 'plugin::webtools.url-pattern' , {
77+ data : {
78+ pattern : '/category/[title]' ,
79+ label : 'Category API pattern' ,
80+ code : 'category_api_pattern' ,
81+ contenttype : 'api::category.category' ,
82+ languages : [ ] ,
83+ } ,
84+ } ) ;
85+
86+ await strapi . entityService . create ( 'plugin::webtools.url-pattern' , {
87+ data : {
88+ pattern : '/private-category/[title]' ,
89+ label : 'Private category API pattern' ,
90+ code : 'private_category_api_pattern' ,
91+ contenttype : 'api::private-category.private-category' ,
92+ languages : [ ] ,
93+ } ,
94+ } ) ;
95+
96+ const privateCategory = await strapi . entityService . create ( 'api::private-category.private-category' , {
97+ data : {
98+ title : 'Published' ,
99+ publishedAt : new Date ( ) ,
100+ } ,
101+ } ) ;
102+
103+ const publishedCategory = await strapi . entityService . create ( 'api::category.category' , {
104+ data : {
105+ title : 'Published category' ,
106+ publishedAt : new Date ( ) ,
107+ } ,
108+ } ) ;
109+
110+ const unpublishedCategory = await strapi . entityService . create ( 'api::category.category' , {
111+ data : {
112+ title : 'Unpublished category' ,
113+ } ,
114+ } ) ;
115+
116+ await strapi . entityService . create ( 'api::test.test' , {
117+ data : {
118+ title : 'Published test page' ,
119+ publishedAt : new Date ( ) ,
120+ category : unpublishedCategory . id ,
121+ private_category : privateCategory . id ,
122+ } ,
123+ } ) ;
124+
125+ await strapi . entityService . create ( 'api::test.test' , {
126+ data : {
127+ title : 'Unpublished test page' ,
128+ category : publishedCategory . id ,
129+ } ,
130+ } ) ;
131+ }
132+ } ,
20133} ;
0 commit comments