forked from strapi/strapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cypress in monorepo and split by package
- Loading branch information
Showing
20 changed files
with
1,468 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"chromeWebSecurity": false, | ||
"backendUrl": "http://localhost:1337", | ||
"baseUrl": "http://localhost:1337", | ||
"frontLoadingDelay": 3000, | ||
"animDelay": 1000, | ||
"serverRestartDelay": 11000, | ||
"viewportHeight": 900, | ||
"viewportWidth": 1440, | ||
"integrationFolder": "./packages" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "category", | ||
"description": "", | ||
"connection": "default", | ||
"attributes": [ | ||
{ | ||
"name": "name", | ||
"params": { | ||
"required": true, | ||
"unique": true, | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"name": "products", | ||
"params": { | ||
"key": "category", | ||
"nature": "oneToMany", | ||
"target": "product" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "product", | ||
"description": "", | ||
"connection": "default", | ||
"attributes": [ | ||
{ | ||
"name": "name", | ||
"params": { | ||
"required": true, | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"name": "description", | ||
"params": { | ||
"type": "text", | ||
"appearance": { | ||
"WYSIWYG": false | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "price", | ||
"params": { | ||
"type": "integer", | ||
"default": 0 | ||
} | ||
}, | ||
{ | ||
"name": "bool", | ||
"params": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
{ | ||
"name": "bool1", | ||
"params": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
{ | ||
"name": "email", | ||
"params": { | ||
"type": "email" | ||
} | ||
}, | ||
{ | ||
"name": "tags", | ||
"params": { | ||
"dominant": true, | ||
"key": "products", | ||
"nature": "manyToMany", | ||
"target": "tag" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "tag", | ||
"description": "", | ||
"connection": "default", | ||
"attributes": [ | ||
{ | ||
"name": "name", | ||
"params": { | ||
"required": true, | ||
"type": "string" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"name": "cat1" | ||
}, | ||
{ | ||
"name": "cat2" | ||
}, | ||
{ | ||
"name": "cat3" | ||
}, | ||
{ | ||
"name": "drinks" | ||
}, | ||
{ | ||
"name": "french food" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"name": "name", | ||
"description": "This is a super description", | ||
"price": 1337, | ||
"bool": true, | ||
"bool1": false, | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "name1", | ||
"description": "This description is not cool", | ||
"price": 4000, | ||
"bool": false, | ||
"bool1": true, | ||
"email": "[email protected]" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"name": "tag1" | ||
}, | ||
{ | ||
"name": "tag2" | ||
}, | ||
{ | ||
"name": "tag3" | ||
}, | ||
{ | ||
"name": "special tag" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add("login", (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is will overwrite an existing command -- | ||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) | ||
const stringify = JSON.stringify; | ||
const backendUrl = Cypress.config('backendUrl'); | ||
const serverRestartDelay = Cypress.config('serverRestartDelay'); | ||
|
||
Cypress.Commands.add('createUser', () => { | ||
const user = { | ||
username: 'soup', | ||
email: '[email protected]', | ||
password: 'coucou123', | ||
}; | ||
|
||
return cy.request({ url: `${backendUrl}/users-permissions/init`, method: 'GET' }) | ||
.then(response => { | ||
const { body: { hasAdmin } } = response; | ||
|
||
if (!hasAdmin) { | ||
// Create one | ||
cy.request({ url: `${backendUrl}/auth/local/register`, method: 'POST', body: user }); | ||
} | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('checkModalOpening', () => { | ||
return cy.get('.modal').invoke('show'); | ||
}) | ||
|
||
Cypress.Commands.add('deleteUser', (id, jwt) => { | ||
cy.request({ | ||
url: `${backendUrl}/users/${id}`, | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: `Bearer ${jwt}` | ||
} | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('createProductAndTagApis', (jwt = null) => { | ||
return cy | ||
.fixture('api/tag.json') | ||
.then(body => { | ||
return cy.request({ | ||
url: `${backendUrl}/content-type-builder/models`, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${jwt}` | ||
}, | ||
body, | ||
}) | ||
.wait(serverRestartDelay) | ||
.fixture('api/product.json') | ||
.then(body => { | ||
return cy.request({ | ||
url: `${backendUrl}/content-type-builder/models`, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${jwt}` | ||
}, | ||
body, | ||
}) | ||
.wait(serverRestartDelay); | ||
}); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('createCTMApis', (jwt = null) => { | ||
return cy | ||
.createProductAndTagApis(jwt) | ||
.wait(serverRestartDelay) | ||
.fixture('api/category.json') | ||
.then(body => { | ||
return cy | ||
.request({ | ||
url: `${backendUrl}/content-type-builder/models`, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${jwt}`, | ||
}, | ||
body, | ||
}) | ||
.wait(serverRestartDelay); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('deleteAllModelData', (model, jwt, source = null) => { | ||
// GET all data; | ||
cy.request({ | ||
url: `${backendUrl}/content-manager/explorer/${model}`, | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${jwt}`, | ||
}, | ||
}) | ||
.then(data => { | ||
const entriesToDelete = data.body.reduce((acc, curr) => { | ||
return acc.concat(curr.id); | ||
}, []); | ||
|
||
const qs = Object.assign(entriesToDelete, source ? { source } : {}); | ||
|
||
return cy.request({ | ||
url: `${backendUrl}/content-manager/explorer/deleteAll/${model}`, | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: `Bearer ${jwt}`, | ||
}, | ||
qs, | ||
}); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('deleteApi', (model, jwt) => { | ||
return cy.request({ | ||
url: `${backendUrl}/content-type-builder/models/${model}`, | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: `Bearer ${jwt}` | ||
}, | ||
}) | ||
.wait(serverRestartDelay); | ||
}); | ||
|
||
Cypress.Commands.add('login', () => { | ||
cy.createUser() | ||
return cy.request({ | ||
url: `${backendUrl}/auth/local`, | ||
method: 'POST', | ||
body: { | ||
identifier: 'soup', | ||
password: 'coucou123', | ||
}, | ||
}) | ||
.then(response => { | ||
window.localStorage.setItem('jwtToken', stringify(response.body.jwt)); | ||
window.localStorage.setItem('userInfo', stringify(response.body.user)); | ||
|
||
return response.body; | ||
}) | ||
}); | ||
|
||
Cypress.Commands.add('seedData', (model, jwt, source = null) => { | ||
return cy | ||
.fixture(`seeds/${model}.json`) | ||
.then(seed => { | ||
seed.forEach(body => { | ||
cy.request({ | ||
method: 'POST', | ||
url: `${backendUrl}/content-manager/explorer/${model}?source='content-manager`, | ||
headers: { | ||
Authorization: `Bearer ${jwt}`, | ||
}, | ||
body, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('submitForm', () => { | ||
return cy.get('form').submit(); | ||
}); |
Oops, something went wrong.