This file contains hidden or 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
const request = require("supertest"); | |
// function from gist file | |
const { setupStrapi } = require("./helpers/strapi"); | |
// We're setting timeout because sometimes bootstrap can take 5-7 seconds (big apps) | |
jest.setTimeout(10000); | |
let app; // this is instance of the the strapi | |
beforeAll(async () => { |
This file contains hidden or 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
image: node:alpine | |
test: | |
stage: test | |
image: node:alpine | |
before_script: | |
- npm install | |
script: | |
- npm run test-ci | |
artifacts: |
This file contains hidden or 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
/** | |
* Default data that factory use | |
*/ | |
const defaultData = { | |
password: "1234Abc", | |
provider: "local", | |
confirmed: true, | |
}; | |
/** | |
* Returns random username object for user creation |
This file contains hidden or 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
const Strapi = require("strapi"); | |
const http = require("http"); | |
let instance; | |
jest.setTimeout(30000); | |
/** | |
* Setups strapi for futher testing | |
*/ | |
async function setupStrapi() { |
This file contains hidden or 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
{ | |
"routes": [ | |
{ | |
"method": "GET", | |
"path": "/hi", | |
"handler": "Hello.hi", | |
"config": { | |
"policies": ["plugins::users-permissions.isAuthenticated"] | |
} | |
} |
This file contains hidden or 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
module.exports = { | |
hi: (ctx) => { | |
ctx.send(`Hi ${ctx.state.user.username}`); | |
}, | |
}; |
This file contains hidden or 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
it("should return `Hi ${user.username}`", async (done) => { | |
const token = await jwt(user.id); | |
await request(strapi.server) // app server is and instance of Class: http.Server | |
.get("/hi") | |
.set("Authorization", "Bearer " + token) | |
.expect(200) // Expect response http code 200 | |
.then((data) => { | |
expect(data.text).toBe(`Hi ${user.username}`); // expect the response welcome text | |
}); | |
done(); |
This file contains hidden or 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
beforeAll(async (done) => { | |
user = await userFactory.createUser(strapi); | |
await grantPrivilage(1, "permissions.application.controllers.hello.hi"); | |
done(); | |
}); |
This file contains hidden or 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
module.exports = ({ env }) => ({ | |
email: { | |
provider: "mocknodemailer", | |
providerOptions: {}, | |
settings: {}, | |
}, | |
}); |
This file contains hidden or 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
const request = require("supertest"); | |
const userFactory = require("./../user/factory"); | |
const { jwt, grantPrivilage } = require("./../helpers/strapi"); | |
describe("Hello methods", () => { | |
let user; | |
beforeAll(async (done) => { | |
user = await userFactory.createUser(strapi); | |
await grantPrivilage(1, "permissions.application.controllers.hello.hi"); // 1 is default role for new confirmed users | |
done(); |