Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require("axios");
- const { expect } = require("chai");
- const { URL_API, URL_USERS_LOGIN } = require("./urls");
- // Логин с правильной почтой и паролем
- describe("login with valid email and password", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- email: "hudokormovae@gmail.com",
- password: "FLNE6PKm"
- })
- .then(response => {
- res = response;
- done();
- })
- .catch(error => {
- done(error);
- });
- });
- it("should return 200 status ", () => {
- expect(res.status).to.be.equal(200);
- });
- it("should return id field", () => {
- expect(res.data).to.have.property("id");
- expect(res.data.id).to.be.a("number");
- });
- it("should return email field", () => {
- expect(res.data).to.have.property("email");
- expect(res.data.email).to.be.a("string");
- });
- it("should return is_authorized field", () => {
- expect(res.data).to.have.property("is_authorized");
- expect(res.data.is_authorized).to.be.a("boolean");
- });
- it("should return is_email_verified field", () => {
- expect(res.data).to.have.property("is_email_verified");
- expect(res.data.is_email_verified).to.be.a("boolean");
- });
- it("should return is_login_confirm_enabled field", () => {
- expect(res.data).to.have.property("is_login_confirm_enabled");
- expect(res.data.is_login_confirm_enabled).to.be.a("boolean");
- });
- it("should return theme field", () => {
- expect(res.data).to.have.property("theme");
- expect(res.data.theme).to.satisfy(value => {
- return typeof value === "string" || value === null;
- });
- });
- it("should return first_name field", () => {
- expect(res.data).to.have.property("first_name");
- expect(res.data.first_name).to.be.a("string");
- });
- it("should return last_name field", () => {
- expect(res.data).to.have.property("last_name");
- expect(res.data.last_name).to.be.a("string");
- });
- it("should return is_email_verified field", () => {
- expect(res.data).to.have.property("is_email_verified");
- expect(res.data.is_email_verified).to.be.a("boolean");
- });
- it("should return language field", () => {
- expect(res.data).to.have.property("language");
- expect(res.data.language).to.be.a("string");
- });
- it("should return billing_policy_id field", () => {
- expect(res.data).to.have.property("billing_policy_id");
- expect(res.data.billing_policy_id).to.be.a("string");
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.have.property("set-cookie");
- expect(res.headers["set-cookie"]).to.be.a("array");
- expect(res.headers["set-cookie"].join("")).to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).to.include("sessionid");
- });
- });
- // Логин с верным паролем и неверной почтой
- describe("login with not valid email", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- email: "hudokormova34e@gmail.com",
- password: "FLNE6PKm"
- })
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value AUTHENTICATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
- });
- });
- // Логин с верной почтой и неверным паролем
- describe("login with not valid password", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- email: "hudokormovae@gmail.com",
- password: "Km"
- })
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value AUTHENTICATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
- });
- });
- // Логин с неверными логином и паролем
- describe("login with not valid email and password", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- email: "hudoormovae@l.com",
- password: "Km"
- })
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value AUTHENTICATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
- });
- });
- // Логин с верным паролем и без почты
- describe("login with valid password and withot email", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- password: "FLNE6PKm"
- })
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value VALIDATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
- });
- });
- // Логин с верной почтой и без пароля
- describe("login with valid email and withot password", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {
- email: "hudokormovae@gmail.com"
- })
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value VALIDATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
- });
- });
- // Логин без почты и пароля
- describe("login withot email and password", () => {
- let res = null;
- before(done => {
- axios
- .post(URL_API + URL_USERS_LOGIN, {})
- .then(response => {
- done(new Error("Unexpected success code 200"));
- })
- .catch(error => {
- res = error.response;
- done();
- });
- });
- it("should return 400 status ", () => {
- expect(res.status).to.be.equal(400);
- });
- it("should return set-cookie field", () => {
- expect(res.headers).to.be.property("set-cookie");
- expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
- expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
- });
- it("should return error_type field with value VALIDATION_ERROR", () => {
- expect(res.data).to.have.property("error_type");
- expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement