· 5 years ago · Sep 05, 2020, 05:02 PM
1const MB = require("../lib/mindbody-sdk")
2const chai = require("chai")
3const expect = chai.expect
4
5const userid = "testUser";
6const testPw = "testPassword";
7const fakeAPIKey = "4c8213d510ee4a8eac07d483950804e4";
8const siteID = -99
9
10describe("Issue User Token", function () {
11
12 describe("Incomplete Class Creation", function () {
13 it("Should throw an error when no api key is given", async function () {
14 const mbo = new MB({
15 SiteId: siteID
16 });
17 try {
18 await mbo.usertoken.issue({ Username: userid, Password: testPw })
19 throw new Error("This will not run")
20 } catch (e) {
21 expect(e).to.be.instanceOf(Error)
22 expect(e).to.have.property("status")
23 expect(e).to.have.property("statusText")
24 expect(e).to.have.property("url")
25 }
26 })
27
28 it("Should throw an error when no site ID key is given", async function () {
29 const mbo = new MB({
30 ApiKey: fakeAPIKey
31 })
32 try {
33 await mbo.usertoken.issue({ Username: userid, Password: testPw })
34 throw new Error("This will not run")
35 } catch (e) {
36 expect(e).to.be.instanceOf(Error)
37 expect(e).to.have.property("status")
38 expect(e).to.have.property("statusText")
39 expect(e).to.have.property("url")
40 }
41 })
42 })
43 describe("Valid Class Creation", function () {
44 const validMbo = new MB({
45 ApiKey: fakeAPIKey,
46 SiteId: -99
47 })
48 describe("Incorrect user login details are given",function () {
49
50 it("Should throw an error when there is no password", async function () {
51 try {
52 await validMbo.usertoken.issue({ Username: userid })
53 throw new Error("This will not run")
54 } catch (e) {
55 expect(e).to.be.instanceOf(Error)
56 expect(e).to.have.property("status")
57 expect(e).to.have.property("statusText")
58 expect(e).to.have.property("url")
59 }
60 })
61 it("Should throw an error when there is no username", async function () {
62 try {
63 await validMbo.usertoken.issue({ Password: testPw })
64 throw new Error("This will not run")
65 } catch (e) {
66 expect(e).to.be.instanceOf(Error)
67 expect(e).to.have.property("status")
68 expect(e).to.have.property("statusText")
69 expect(e).to.have.property("url")
70 }
71 })
72 it("Should throw an error when the password is incorrect", async function () {
73 const badPassword = "FakePassword"
74 try {
75 await validMbo.usertoken.issue({ Username: userid, Password: badPassword })
76 throw new Error("This will not run")
77 } catch (e) {
78 expect(e).to.be.instanceOf(Error)
79 expect(e).to.have.property("status")
80 expect(e).to.have.property("statusText")
81 expect(e).to.have.property("url")
82 }
83 })
84 })
85
86 })
87})
88