See More

import { cb } from "./utils"; describe("ClearBlade initialization should", function() { beforeEach(function() { var initOptions = { systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret" }; cb.init(initOptions); }); it("have the systemKey stored", function() { expect(cb.systemKey).toEqual("fakeSystemKey"); }); it("have the systemSecret stored", function() { expect(cb.systemSecret).toEqual("fakeSystemSecret"); }); it("have defaulted the URI to the Platform", function() { expect(cb.URI).toEqual("https://platform.clearblade.com"); }); it("have defaulted the logging to false", function() { expect(cb.logging).toEqual(false); }); it("have defaulted the callTimeout to 30000", function() { expect(cb._callTimeout).toEqual(30000); }); }); describe("ClearBlade user setup", function() { beforeEach(function() { var initOptions = { systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret" }; cb.init(initOptions); }); it("should register a new user correctly", function() { var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later cb.registerUser("[email protected]", "testPass", function(err, data) {}); var expectedData = { method: "POST", endpoint: "api/v/1/user/reg", useUser: true, user: { email: "[email protected]", authToken: undefined }, systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", authToken: undefined, timeout: 30000, URI: "https://platform.clearblade.com", body: { email: "[email protected]", password: "testPass" } }; // expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData); expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData); }); it("should login as anon", function() { var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later cb.loginAnon(function(err, data) {}); var expectedData = { method: "POST", endpoint: "api/v/1/user/anon", useUser: false, systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", timeout: 30000, URI: "https://platform.clearblade.com" }; expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData); }); it("should login as user", function() { var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later var initOptions = { systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", email: "[email protected]", password: "testPass" }; cb.init(initOptions); var expectedData = { method: "POST", endpoint: "api/v/1/user/auth", useUser: false, systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", timeout: 30000, URI: "https://platform.clearblade.com", body: { email: "[email protected]", password: "testPass" } }; expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData); }); it("should check to see if the user is authed", function() { cb.setUser("[email protected]", "testUserToken"); var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later cb.isCurrentUserAuthenticated(function(err, data) {}); var expectedData = { method: "POST", endpoint: "api/v/1/user/checkauth", systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", timeout: 30000, URI: "https://platform.clearblade.com", user: { email: "[email protected]", authToken: "testUserToken" } }; expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData); }); it("should log out user", function() { cb.setUser("[email protected]", "testUserToken"); var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later cb.logoutUser(function(err, data) {}); var expectedData = { method: "POST", endpoint: "api/v/1/user/logout", systemKey: "fakeSystemKey", systemSecret: "fakeSystemSecret", timeout: 30000, URI: "https://platform.clearblade.com", user: { email: "[email protected]", authToken: "testUserToken" } }; expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData); }); });