// (C) 2007-2020 GoodData Corporation import * as request from "supertest"; import { pick } from "lodash"; import { bootstrap } from "../bootstrap"; import { createEndpoint } from "../../../utils/tests"; import { ISchema } from "../../../schema/model/Schema"; const defaultUsers = [ { identifier: "123456", email: "john.doe@example.com", }, ]; const defaultProject = { title: "My title", identifier: "mymockproject", permissions: { canSetLocale: false, canSeePublicAccessCode: true, }, }; function createBootstrapEndpoint(project = defaultProject, users = defaultUsers) { const schema: ISchema = { project, users, }; return createEndpoint(bootstrap, schema); } describe("bootstrap", () => { const app = createBootstrapEndpoint(); it("should return bootstrap", done => { request(app) .get("/gdc/app/account/bootstrap") .expect(200) .end((err, res) => { expect(err).toBe(null); expect(res.body.bootstrapResource.accountSetting).toEqual({ authenticationModes: [], companyName: "Birst", country: null, created: "2014-07-01 15:16:05", effectiveIpWhitelist: null, email: "john.doe@example.com", firstName: "John", ipWhitelist: null, language: "en-US", lastName: "Doe", links: { self: "/gdc/account/profile/123456", }, login: "john.doe@example.com", phoneNumber: "123 123 123", position: null, timezone: null, updated: "2017-01-03 14:15:39", }); const actualProjectPermissions = pick( res.body.bootstrapResource.current.projectPermissions.permissions, ["canSetLocale", "canSeePublicAccessCode"], ); expect(actualProjectPermissions).toEqual({ canSetLocale: "0", canSeePublicAccessCode: "1", }); done(); }); }); it("should not return bootstrap if project not found", done => { request(app) .get("/gdc/app/account/bootstrap?projectUri=/gdc/projects/notfound") .end((_err, res) => { expect(res.status).toEqual(404); done(); }); }); it("should return bootstrap if project found", done => { const projectUri = "/gdc/projects/mymockproject"; request(app) .get(`/gdc/app/account/bootstrap?projectUri=${projectUri}`) .end((_err, res) => { expect(res.status).toEqual(200); const receivedProject = res.body.bootstrapResource.current.project.links.self; expect(receivedProject).toEqual(projectUri); done(); }); }); it("should return bootstrap with mapbox token", done => { request(app) .get("/gdc/app/account/bootstrap") .expect(200) .end((err, res) => { expect(err).toBe(null); // it is "dummy_mapbox_token" in local run but it is real token in ci run expect(res.body.bootstrapResource.current.mapboxToken).toEqual(expect.any(String)); done(); }); }); });