Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require("axios");
  2. const { expect } = require("chai");
  3. const { URL_API, URL_USERS_LOGIN } = require("./urls");
  4.  
  5. // Логин с правильной почтой и паролем
  6.  
  7. describe("login with valid email and password", () => {
  8.   let res = null;
  9.  
  10.   before(done => {
  11.     axios
  12.       .post(URL_API + URL_USERS_LOGIN, {
  13.         email: "hudokormovae@gmail.com",
  14.         password: "FLNE6PKm"
  15.       })
  16.       .then(response => {
  17.         res = response;
  18.         done();
  19.       })
  20.       .catch(error => {
  21.         done(error);
  22.       });
  23.   });
  24.  
  25.   it("should return 200 status ", () => {
  26.     expect(res.status).to.be.equal(200);
  27.   });
  28.  
  29.   it("should return id field", () => {
  30.     expect(res.data).to.have.property("id");
  31.     expect(res.data.id).to.be.a("number");
  32.   });
  33.  
  34.   it("should return email field", () => {
  35.     expect(res.data).to.have.property("email");
  36.     expect(res.data.email).to.be.a("string");
  37.   });
  38.  
  39.   it("should return is_authorized field", () => {
  40.     expect(res.data).to.have.property("is_authorized");
  41.     expect(res.data.is_authorized).to.be.a("boolean");
  42.   });
  43.  
  44.   it("should return is_email_verified field", () => {
  45.     expect(res.data).to.have.property("is_email_verified");
  46.     expect(res.data.is_email_verified).to.be.a("boolean");
  47.   });
  48.  
  49.   it("should return is_login_confirm_enabled field", () => {
  50.     expect(res.data).to.have.property("is_login_confirm_enabled");
  51.     expect(res.data.is_login_confirm_enabled).to.be.a("boolean");
  52.   });
  53.  
  54.   it("should return theme field", () => {
  55.     expect(res.data).to.have.property("theme");
  56.     expect(res.data.theme).to.satisfy(value => {
  57.       return typeof value === "string" || value === null;
  58.     });
  59.   });
  60.  
  61.   it("should return first_name field", () => {
  62.     expect(res.data).to.have.property("first_name");
  63.     expect(res.data.first_name).to.be.a("string");
  64.   });
  65.  
  66.   it("should return last_name field", () => {
  67.     expect(res.data).to.have.property("last_name");
  68.     expect(res.data.last_name).to.be.a("string");
  69.   });
  70.  
  71.   it("should return is_email_verified field", () => {
  72.     expect(res.data).to.have.property("is_email_verified");
  73.     expect(res.data.is_email_verified).to.be.a("boolean");
  74.   });
  75.  
  76.   it("should return language field", () => {
  77.     expect(res.data).to.have.property("language");
  78.     expect(res.data.language).to.be.a("string");
  79.   });
  80.  
  81.   it("should return billing_policy_id field", () => {
  82.     expect(res.data).to.have.property("billing_policy_id");
  83.     expect(res.data.billing_policy_id).to.be.a("string");
  84.   });
  85.  
  86.   it("should return set-cookie field", () => {
  87.     expect(res.headers).to.have.property("set-cookie");
  88.     expect(res.headers["set-cookie"]).to.be.a("array");
  89.     expect(res.headers["set-cookie"].join("")).to.include("csrftoken");
  90.     expect(res.headers["set-cookie"].join("")).to.include("sessionid");
  91.   });
  92. });
  93.  
  94. // Логин с верным паролем и неверной почтой
  95.  
  96. describe("login with not valid email", () => {
  97.   let res = null;
  98.  
  99.   before(done => {
  100.     axios
  101.       .post(URL_API + URL_USERS_LOGIN, {
  102.         email: "hudokormova34e@gmail.com",
  103.         password: "FLNE6PKm"
  104.       })
  105.       .then(response => {
  106.         done(new Error("Unexpected success code 200"));
  107.       })
  108.       .catch(error => {
  109.         res = error.response;
  110.         done();
  111.       });
  112.   });
  113.  
  114.   it("should return 400 status ", () => {
  115.     expect(res.status).to.be.equal(400);
  116.   });
  117.  
  118.   it("should return set-cookie field", () => {
  119.     expect(res.headers).to.be.property("set-cookie");
  120.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  121.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  122.   });
  123.  
  124.   it("should return error_type field with value AUTHENTICATION_ERROR", () => {
  125.     expect(res.data).to.have.property("error_type");
  126.     expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
  127.   });
  128. });
  129.  
  130. // Логин с верной почтой и неверным паролем
  131.  
  132. describe("login with not valid password", () => {
  133.   let res = null;
  134.  
  135.   before(done => {
  136.     axios
  137.       .post(URL_API + URL_USERS_LOGIN, {
  138.         email: "hudokormovae@gmail.com",
  139.         password: "Km"
  140.       })
  141.       .then(response => {
  142.         done(new Error("Unexpected success code 200"));
  143.       })
  144.       .catch(error => {
  145.         res = error.response;
  146.         done();
  147.       });
  148.   });
  149.  
  150.   it("should return 400 status ", () => {
  151.     expect(res.status).to.be.equal(400);
  152.   });
  153.  
  154.   it("should return set-cookie field", () => {
  155.     expect(res.headers).to.be.property("set-cookie");
  156.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  157.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  158.   });
  159.  
  160.   it("should return error_type field with value AUTHENTICATION_ERROR", () => {
  161.     expect(res.data).to.have.property("error_type");
  162.     expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
  163.   });
  164. });
  165.  
  166. // Логин с неверными логином и паролем
  167.  
  168. describe("login with not valid email and password", () => {
  169.   let res = null;
  170.  
  171.   before(done => {
  172.     axios
  173.       .post(URL_API + URL_USERS_LOGIN, {
  174.         email: "hudoormovae@l.com",
  175.         password: "Km"
  176.       })
  177.       .then(response => {
  178.         done(new Error("Unexpected success code 200"));
  179.       })
  180.       .catch(error => {
  181.         res = error.response;
  182.         done();
  183.       });
  184.   });
  185.  
  186.   it("should return 400 status ", () => {
  187.     expect(res.status).to.be.equal(400);
  188.   });
  189.  
  190.   it("should return set-cookie field", () => {
  191.     expect(res.headers).to.be.property("set-cookie");
  192.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  193.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  194.   });
  195.  
  196.   it("should return error_type field with value AUTHENTICATION_ERROR", () => {
  197.     expect(res.data).to.have.property("error_type");
  198.     expect(res.data.error_type).to.be.equal("AUTHENTICATION_ERROR");
  199.   });
  200. });
  201.  
  202. // Логин с верным паролем и без почты
  203.  
  204. describe("login with valid password and withot email", () => {
  205.   let res = null;
  206.  
  207.   before(done => {
  208.     axios
  209.       .post(URL_API + URL_USERS_LOGIN, {
  210.         password: "FLNE6PKm"
  211.       })
  212.       .then(response => {
  213.         done(new Error("Unexpected success code 200"));
  214.       })
  215.       .catch(error => {
  216.         res = error.response;
  217.         done();
  218.       });
  219.   });
  220.  
  221.   it("should return 400 status ", () => {
  222.     expect(res.status).to.be.equal(400);
  223.   });
  224.  
  225.   it("should return set-cookie field", () => {
  226.     expect(res.headers).to.be.property("set-cookie");
  227.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  228.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  229.   });
  230.  
  231.   it("should return error_type field with value VALIDATION_ERROR", () => {
  232.     expect(res.data).to.have.property("error_type");
  233.     expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
  234.   });
  235. });
  236.  
  237. // Логин с верной почтой и без пароля
  238.  
  239. describe("login with valid email and withot password", () => {
  240.   let res = null;
  241.  
  242.   before(done => {
  243.     axios
  244.       .post(URL_API + URL_USERS_LOGIN, {
  245.         email: "hudokormovae@gmail.com"
  246.       })
  247.       .then(response => {
  248.         done(new Error("Unexpected success code 200"));
  249.       })
  250.       .catch(error => {
  251.         res = error.response;
  252.         done();
  253.       });
  254.   });
  255.  
  256.   it("should return 400 status ", () => {
  257.     expect(res.status).to.be.equal(400);
  258.   });
  259.  
  260.   it("should return set-cookie field", () => {
  261.     expect(res.headers).to.be.property("set-cookie");
  262.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  263.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  264.   });
  265.  
  266.   it("should return error_type field with value VALIDATION_ERROR", () => {
  267.     expect(res.data).to.have.property("error_type");
  268.     expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
  269.   });
  270. });
  271.  
  272. // Логин без почты и пароля
  273.  
  274. describe("login withot email and password", () => {
  275.   let res = null;
  276.  
  277.   before(done => {
  278.     axios
  279.       .post(URL_API + URL_USERS_LOGIN, {})
  280.       .then(response => {
  281.         done(new Error("Unexpected success code 200"));
  282.       })
  283.       .catch(error => {
  284.         res = error.response;
  285.         done();
  286.       });
  287.   });
  288.  
  289.   it("should return 400 status ", () => {
  290.     expect(res.status).to.be.equal(400);
  291.   });
  292.  
  293.   it("should return set-cookie field", () => {
  294.     expect(res.headers).to.be.property("set-cookie");
  295.     expect(res.headers["set-cookie"].join("")).not.to.include("csrftoken");
  296.     expect(res.headers["set-cookie"].join("")).not.to.include("sessionid");
  297.   });
  298.  
  299.   it("should return error_type field with value VALIDATION_ERROR", () => {
  300.     expect(res.data).to.have.property("error_type");
  301.     expect(res.data.error_type).to.be.equal("VALIDATION_ERROR");
  302.   });
  303. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement