// (C) 2007-2020 GoodData Corporation import * as request from "supertest"; import { profile, CURRENT_USER_PSEUDO_ID } from "../profile"; import { createEndpoint } from "../../../utils/tests"; import { ISchema } from "../../../schema/model/Schema"; it.each` name | identifier | uriPart ${"existing"} | ${"123456"} | ${"123456"} ${"current"} | ${"123456"} | ${CURRENT_USER_PSEUDO_ID} `("should return $name profile", ({ identifier, uriPart }) => { const schema: ISchema = { project: { title: "My title", }, users: [ { identifier, email: "john.doe@example.com", }, { identifier: `some_other_${identifier}`, email: "jane.doe@example.com", }, ], }; const app = createEndpoint(profile, schema); return request(app) .get(`/gdc/account/profile/${uriPart}`) .then(res => { expect(res.body).toEqual({ accountSetting: { 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", }, }); }); }); it("should return 404 in case profile not found", () => { const schema: ISchema = { project: { title: "My title", }, users: [], }; const app = createEndpoint(profile, schema); return request(app) .get("/gdc/account/profile/xyz-unknown-profile") .expect(404) .then(res => { expect(res.body).toEqual({ error: { parameters: ["xyz-unknown-profile"], component: "GDC::LWP::UserAgent", errorClass: "GDC::Exception::NotFound", message: "User uid %s doesn't exist.", }, }); }); }); it.each` name | identifier | uriPart ${"existing"} | ${"123456"} | ${"123456"} ${"current"} | ${"123456"} | ${CURRENT_USER_PSEUDO_ID} `("should accept saving of $name profile settings", ({ identifier, uriPart }) => { const schema: ISchema = { project: { title: "My title", }, users: [ { identifier, email: "john.doe@example.com", }, { identifier: `some_other_${identifier}`, email: "jane.doe@example.com", }, ], }; const app = createEndpoint(profile, schema); return request(app) .put(`/gdc/account/profile/${uriPart}/settings`) .expect(204) .then(res => { expect(res.body).toEqual({}); }); }); it("should reject saving of the profile settings if profile not found", () => { const schema: ISchema = { project: { title: "My title", }, users: [ { identifier: "123456", email: "john.doe@example.com", }, ], }; const app = createEndpoint(profile, schema); return request(app) .put("/gdc/account/profile/xyz-unknown-profile/settings") .expect(404) .then(res => { expect(res.body).toEqual({ error: { parameters: ["xyz-unknown-profile"], component: "GDC::LWP::UserAgent", errorClass: "GDC::Exception::NotFound", message: "User uid %s doesn't exist.", }, }); }); });