Skip to content

Instantly share code, notes, and snippets.

View qunabu's full-sized avatar

Mateusz Wojczal qunabu

View GitHub Profile
@qunabu
qunabu / test-e2e.js
Created November 26, 2020 09:23
Test e2e
// TEST. framework cypress
describe("My First Test", () => {
it("Gets, types and asserts", () => {
cy.visit("https://example.cypress.io");
cy.contains("type").click();
// Should be on a new URL which includes '/commands/actions'
cy.url().should("include", "/commands/actions");
// Get an input, type into it and verify that the value has been updated
cy.get(".action-email")
.type("[email protected]")
@qunabu
qunabu / integration-test.js
Created November 26, 2020 09:22
Test integracyjny
// app
const request = require("supertest");
const app = require("express")();
app.get("/user", (req, res) => res.status(200).json({ name: "john" }));
// TEST. framework jest
request(app)
.get("/user")
.expect("Content-Type", /json/)
@qunabu
qunabu / test.js
Created November 26, 2020 09:15
Test jednostkowy
// app
const add = (a, b) => a + b;
// TEST. framework jest
expect(add(2, 2)).toBe(4);
const request = require("supertest");
const userFactory = require("./../user/factory");
const nodemailerMock = require("nodemailer-mock");
// const { jwt, grantPrivilage } = require("./../helpers/strapi");
describe("Reset password", () => {
let user;
beforeAll(async (done) => {
user = await userFactory.createUser(strapi);
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);
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();
module.exports = ({ env }) => ({
email: {
provider: "mocknodemailer",
providerOptions: {},
settings: {},
},
});
beforeAll(async (done) => {
user = await userFactory.createUser(strapi);
await grantPrivilage(1, "permissions.application.controllers.hello.hi");
done();
});
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();
module.exports = {
hi: (ctx) => {
ctx.send(`Hi ${ctx.state.user.username}`);
},
};