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
const fs = require("fs"); | |
const Strapi = require("strapi"); | |
let instance; | |
async function setupStrapi(entryNamesToOpen) { | |
if (!instance) { | |
//delete test database if exists | |
const testDataBase = `${__dirname}/../../.tmp/test.db`; | |
if (fs.existsSync(testDataBase)) { |
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
/** | |
* Get json from local machine | |
* @param {String} filename on local machine | |
* @returns {Promise} resolved object is JSON | |
*/ | |
const getJSON = filename => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(filename, (err, data) => { | |
if (err) { | |
reject(err); |
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
{ | |
"routes": [ | |
{ | |
"method": "GET", | |
"path": "/hi", | |
"handler": "Hello.hi", | |
"config": { | |
"policies": ["plugins::users-permissions.isAuthenticated"] | |
} | |
} |
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
module.exports = { | |
hi: (ctx) => { | |
ctx.send(`Hi ${ctx.state.user.username}`); | |
}, | |
}; |
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
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 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 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 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(); |
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
const request = require("supertest"); | |
const { updatePluginStore, responseHasError } = require("./../helpers/strapi"); | |
const { createUser, defaultData, mockUserData } = require("./factory"); | |
const nodemailerMock = require("nodemailer-mock"); | |
describe("Default User methods", () => { | |
let user; | |
beforeAll(async (done) => { | |
user = await createUser(strapi); |
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
/** | |
* Default data that factory use | |
*/ | |
const defaultData = { | |
password: "1234Abc", | |
provider: "local", | |
confirmed: true, | |
}; | |
/** | |
* Returns random username object for user creation |