diff --git a/packages/arcgis-rest-portal/test/groups/add-users.test.ts b/packages/arcgis-rest-portal/test/groups/add-users.test.ts index 891655b8b3..0b6c31fcfb 100644 --- a/packages/arcgis-rest-portal/test/groups/add-users.test.ts +++ b/packages/arcgis-rest-portal/test/groups/add-users.test.ts @@ -3,7 +3,7 @@ import { addGroupUsers, - IAddGroupUsersOptions + IAddGroupUsersOptions, } from "../../src/groups/add-users"; import { UserSession } from "@esri/arcgis-rest-auth"; import { encodeParam } from "@esri/arcgis-rest-request"; @@ -31,17 +31,17 @@ describe("add-users", () => { refreshTokenTTL: 1440, username: "casey", password: "123456", - portal: "https://myorg.maps.arcgis.com/sharing/rest" + portal: "https://myorg.maps.arcgis.com/sharing/rest", }); afterEach(fetchMock.restore); - it("should send multiple requests for a long user array", done => { + it("should send multiple requests for a long user array", (done) => { const requests = [createUsernames(0, 25), createUsernames(25, 35)]; const responses = [ { notAdded: ["username1"] }, - { notAdded: ["username30"] } + { notAdded: ["username30"] }, ]; fetchMock.post("*", (url, options) => { @@ -61,26 +61,26 @@ describe("add-users", () => { const params = { id: "group-id", users: createUsernames(0, 35), - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; addGroupUsers(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(responses.length).toEqual(0); expect(result.notAdded).toEqual(["username1", "username30"]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should send multiple requests for a long admin array", done => { + it("should send multiple requests for a long admin array", (done) => { const requests = [createUsernames(0, 25), createUsernames(25, 35)]; const responses = [ { notAdded: ["username1"] }, - { notAdded: ["username30"] } + { notAdded: ["username30"] }, ]; fetchMock.post("*", (url, options) => { @@ -100,24 +100,24 @@ describe("add-users", () => { const params = { id: "group-id", admins: createUsernames(0, 35), - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; addGroupUsers(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(responses.length).toEqual(0); expect(result.notAdded).toEqual(["username1", "username30"]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should send separate requests for users and admins", done => { + it("should send separate requests for users and admins", (done) => { const requests = [ encodeParam("users", ["username1", "username2"]), - encodeParam("admins", ["username3"]) + encodeParam("admins", ["username3"]), ]; fetchMock.post("*", (url, options) => { @@ -136,37 +136,37 @@ describe("add-users", () => { id: "group-id", users: ["username1", "username2"], admins: ["username3"], - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; addGroupUsers(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(result.notAdded).toEqual([]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should return request failure", done => { + it("should return request failure", (done) => { const responses = [ { notAdded: ["username2"] }, { error: { code: 400, messageCode: "ORG_3100", - message: "error message for add-user request" - } + message: "error message for add-user request", + }, }, { notAdded: ["username30"] }, { error: { code: 400, messageCode: "ORG_3200", - message: "error message for add-admin request" - } - } + message: "error message for add-admin request", + }, + }, ]; fetchMock.post("*", () => responses.shift()); @@ -175,11 +175,11 @@ describe("add-users", () => { id: "group-id", users: createUsernames(0, 30), admins: createUsernames(30, 60), - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; addGroupUsers(params) - .then(result => { + .then((result) => { expect(responses.length).toEqual(0); const expectedNotAdded = ["username2", "username30"]; @@ -215,25 +215,25 @@ describe("add-users", () => { done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should not send any request for zero-length username array", done => { + it("should not send any request for zero-length username array", (done) => { const params: IAddGroupUsersOptions = { id: "group-id", users: [], admins: [], - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; - + fetchMock.post("*", () => 200); addGroupUsers(params) - .then(result => { + .then((result) => { expect(fetchMock.called()).toEqual(false); expect(result.notAdded).toEqual([]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); }); diff --git a/packages/arcgis-rest-portal/test/groups/invite-users.test.ts b/packages/arcgis-rest-portal/test/groups/invite-users.test.ts index 53ece21bb8..cb7b5ce522 100644 --- a/packages/arcgis-rest-portal/test/groups/invite-users.test.ts +++ b/packages/arcgis-rest-portal/test/groups/invite-users.test.ts @@ -3,7 +3,7 @@ import { inviteGroupUsers, - IInviteGroupUsersOptions, + IInviteGroupUsersOptions, } from "../../src/groups/invite-users"; import { UserSession } from "@esri/arcgis-rest-auth"; @@ -32,18 +32,15 @@ describe("invite-users", () => { refreshTokenTTL: 1440, username: "casey", password: "123456", - portal: "https://myorg.maps.arcgis.com/sharing/rest" + portal: "https://myorg.maps.arcgis.com/sharing/rest", }); afterEach(fetchMock.restore); - it("should send multiple requests for a long user array", done => { + it("should send multiple requests for a long user array", (done) => { const requests = [createUsernames(0, 25), createUsernames(25, 35)]; - const responses = [ - { success: true }, - { success: false } - ]; + const responses = [{ success: true }, { success: false }]; fetchMock.post("*", (url, options) => { expect(url).toEqual( @@ -64,48 +61,48 @@ describe("invite-users", () => { const params: IInviteGroupUsersOptions = { id: "group-id", users: createUsernames(0, 35), - role: 'group_member', + role: "group_member", expiration: 1440, - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; inviteGroupUsers(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(responses.length).toEqual(0); expect(result.success).toEqual(false); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should return request failure", done => { + it("should return request failure", (done) => { const responses = [ { success: true }, { error: { code: 400, messageCode: "ORG_3100", - message: "error message for add-user request" - } + message: "error message for add-user request", + }, }, ]; - fetchMock.post("*", (url, options) => { - return responses.shift(); + fetchMock.post("*", (url, options) => { + return responses.shift(); }); const params: IInviteGroupUsersOptions = { id: "group-id", users: createUsernames(0, 30), - role: 'group_member', + role: "group_member", expiration: 1440, - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; inviteGroupUsers(params) - .then(result => { + .then((result) => { expect(responses.length).toEqual(0); expect(result.success).toEqual(false); @@ -124,26 +121,26 @@ describe("invite-users", () => { expect(errorAOptions.params.users).toEqual(createUsernames(25, 30)); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should not send any request for zero-length username array", done => { + it("should not send any request for zero-length username array", (done) => { const params: IInviteGroupUsersOptions = { id: "group-id", - role: 'group_member', + role: "group_member", expiration: 1440, users: [], - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; - + fetchMock.post("*", () => 200); inviteGroupUsers(params) - .then(result => { + .then((result) => { expect(fetchMock.called()).toEqual(false); expect(result.success).toEqual(true); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); }); diff --git a/packages/arcgis-rest-portal/test/groups/remove-users.test.ts b/packages/arcgis-rest-portal/test/groups/remove-users.test.ts index 49af3a29eb..d07c53c2dd 100644 --- a/packages/arcgis-rest-portal/test/groups/remove-users.test.ts +++ b/packages/arcgis-rest-portal/test/groups/remove-users.test.ts @@ -3,7 +3,7 @@ import { removeGroupUsers, - IRemoveGroupUsersOptions + IRemoveGroupUsersOptions, } from "../../src/groups/remove-users"; import { UserSession } from "@esri/arcgis-rest-auth"; import { encodeParam } from "@esri/arcgis-rest-request"; @@ -31,17 +31,17 @@ describe("remove-users", () => { refreshTokenTTL: 1440, username: "casey", password: "123456", - portal: "https://myorg.maps.arcgis.com/sharing/rest" + portal: "https://myorg.maps.arcgis.com/sharing/rest", }); afterEach(fetchMock.restore); - it("should send multiple requests for a long user array", done => { + it("should send multiple requests for a long user array", (done) => { const requests = [createUsernames(0, 25), createUsernames(25, 35)]; const responses = [ { notRemoved: ["username1"] }, - { notRemoved: ["username30"] } + { notRemoved: ["username30"] }, ]; fetchMock.post("*", (url, options) => { @@ -61,30 +61,30 @@ describe("remove-users", () => { const params = { id: "group-id", users: createUsernames(0, 35), - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; removeGroupUsers(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(responses.length).toEqual(0); expect(result.notRemoved).toEqual(["username1", "username30"]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should return request failure", done => { + it("should return request failure", (done) => { const responses = [ { notRemoved: ["username2"] }, { error: { code: 400, messageCode: "ORG_3100", - message: "error message for remove-user request" - } - } + message: "error message for remove-user request", + }, + }, ]; fetchMock.post("*", () => responses.shift()); @@ -92,11 +92,11 @@ describe("remove-users", () => { const params = { id: "group-id", users: createUsernames(0, 30), - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; removeGroupUsers(params) - .then(result => { + .then((result) => { expect(responses.length).toEqual(0); const expectedNotAdded = ["username2"]; @@ -117,24 +117,24 @@ describe("remove-users", () => { done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should not send any request for zero-length username array", done => { + it("should not send any request for zero-length username array", (done) => { const params: IRemoveGroupUsersOptions = { id: "group-id", users: [], - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; - + fetchMock.post("*", () => 200); removeGroupUsers(params) - .then(result => { + .then((result) => { expect(fetchMock.called()).toEqual(false); expect(result.notRemoved).toEqual([]); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); }); diff --git a/packages/arcgis-rest-portal/test/items/create.test.ts b/packages/arcgis-rest-portal/test/items/create.test.ts index 91b573a722..374b0a5cb2 100644 --- a/packages/arcgis-rest-portal/test/items/create.test.ts +++ b/packages/arcgis-rest-portal/test/items/create.test.ts @@ -6,7 +6,7 @@ import * as fetchMock from "fetch-mock"; import { createFolder, createItem, - createItemInFolder + createItemInFolder, } from "../../src/items/create"; import { ItemSuccessResponse } from "../mocks/items/item"; @@ -30,14 +30,14 @@ describe("search", () => { refreshTokenTTL: 1440, username: "casey", password: "123456", - portal: "https://myorg.maps.arcgis.com/sharing/rest" + portal: "https://myorg.maps.arcgis.com/sharing/rest", }); const MOCK_USER_REQOPTS = { - authentication: MOCK_USER_SESSION + authentication: MOCK_USER_SESSION, }; - it("should create an item with data", done => { + it("should create an item with data", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { owner: "dbouwman", @@ -48,20 +48,20 @@ describe("search", () => { typeKeywords: ["fake", "kwds"], tags: ["fakey", "mcfakepants"], properties: { - key: "somevalue" + key: "somevalue", }, data: { values: { - key: "value" - } - } + key: "value", + }, + }, }; createItem({ item: fakeItem, owner: "dbouwman", - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -84,12 +84,12 @@ describe("search", () => { done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item without an explicit owner", done => { + it("should create an item without an explicit owner", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { title: "my fake item", @@ -100,14 +100,14 @@ describe("search", () => { typeKeywords: ["fake", "kwds"], tags: ["fakey", "mcfakepants"], properties: { - key: "somevalue" - } + key: "somevalue", + }, }; createItem({ item: fakeItem, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -130,12 +130,12 @@ describe("search", () => { done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item with only a username from auth", done => { + it("should create an item with only a username from auth", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { title: "my fake item", @@ -145,15 +145,15 @@ describe("search", () => { typeKeywords: ["fake", "kwds"], tags: ["fakey", "mcfakepants"], properties: { - key: "somevalue" - } + key: "somevalue", + }, }; // why not just use item.owner?? createItem({ item: fakeItem, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -176,12 +176,12 @@ describe("search", () => { done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item with no tags or typeKeywords", done => { + it("should create an item with no tags or typeKeywords", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { title: "my fake item", @@ -189,14 +189,14 @@ describe("search", () => { snippet: "so very fake", type: "Web Mapping Application", properties: { - key: "somevalue" - } + key: "somevalue", + }, }; createItem({ item: fakeItem, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -215,12 +215,12 @@ describe("search", () => { done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item in a folder", done => { + it("should create an item in a folder", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { owner: "dbouwman", @@ -229,15 +229,15 @@ describe("search", () => { snipped: "so very fake", type: "Web Mapping Application", typeKeywords: ["fake", "kwds"], - tags: ["fakey", "mcfakepants"] + tags: ["fakey", "mcfakepants"], }; createItemInFolder({ owner: "dbouwman", item: fakeItem, folderId: "fe8", - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -256,12 +256,12 @@ describe("search", () => { ); done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item in a folder and pass through arbitrary params", done => { + it("should create an item in a folder and pass through arbitrary params", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { owner: "dbouwman", @@ -270,16 +270,16 @@ describe("search", () => { snipped: "so very fake", type: "Web Mapping Application", typeKeywords: ["fake", "kwds"], - tags: ["fakey", "mcfakepants"] + tags: ["fakey", "mcfakepants"], }; createItemInFolder({ owner: "dbouwman", item: fakeItem, folderId: "fe8", params: { - foo: "bar" + foo: "bar", }, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) .then(() => { expect(fetchMock.called()).toEqual(true); @@ -301,12 +301,12 @@ describe("search", () => { ); done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create an item in a folder when no owner is passed", done => { + it("should create an item in a folder when no owner is passed", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { owner: "casey", @@ -315,11 +315,11 @@ describe("search", () => { snipped: "so very fake", type: "Web Mapping Application", typeKeywords: ["fake", "kwds"], - tags: ["fakey", "mcfakepants"] + tags: ["fakey", "mcfakepants"], }; createItemInFolder({ item: fakeItem, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) .then(() => { expect(fetchMock.called()).toEqual(true); @@ -340,19 +340,19 @@ describe("search", () => { ); done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should create a folder", done => { + it("should create a folder", (done) => { fetchMock.once("*", ItemSuccessResponse); const title = "an amazing folder"; createFolder({ title, - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) - .then(response => { + .then((response) => { expect(fetchMock.called()).toEqual(true); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); expect(url).toEqual( @@ -367,25 +367,26 @@ describe("search", () => { done(); }) - .catch(e => { + .catch((e) => { fail(e); }); }); - it("should throw an error for a multipart request with no file name", done => { + it("should throw an error for a multipart request with no file name", (done) => { fetchMock.once("*", ItemSuccessResponse); const fakeItem = { owner: "casey", title: "my fake item", - type: "Web Mapping Application" + type: "Web Mapping Application", }; + fetchMock.post("*", () => 200); createItemInFolder({ item: fakeItem, file: "some file", multipart: true, // multipart is required for a multipart request filename: "", - ...MOCK_USER_REQOPTS + ...MOCK_USER_REQOPTS, }) .then(() => { fail(); diff --git a/packages/arcgis-rest-portal/test/orgs/notification.test.ts b/packages/arcgis-rest-portal/test/orgs/notification.test.ts index 73ac052d3e..4041956f0e 100644 --- a/packages/arcgis-rest-portal/test/orgs/notification.test.ts +++ b/packages/arcgis-rest-portal/test/orgs/notification.test.ts @@ -4,7 +4,10 @@ import { TOMORROW } from "@esri/arcgis-rest-auth/test/utils"; import * as fetchMock from "fetch-mock"; -import { createOrgNotification, ICreateOrgNotificationOptions } from "../../src/orgs/notification"; +import { + createOrgNotification, + ICreateOrgNotificationOptions, +} from "../../src/orgs/notification"; function createUsernames(start: number, end: number): string[] { const usernames = []; @@ -27,18 +30,15 @@ describe("create-org-notification", () => { refreshTokenTTL: 1440, username: "casey", password: "123456", - portal: "https://myorg.maps.arcgis.com/sharing/rest" + portal: "https://myorg.maps.arcgis.com/sharing/rest", }); afterEach(fetchMock.restore); - it("should send multiple requests for a long user array", done => { + it("should send multiple requests for a long user array", (done) => { const requests = [createUsernames(0, 25), createUsernames(25, 35)]; - const responses = [ - { success: true }, - { success: true } - ]; + const responses = [{ success: true }, { success: true }]; fetchMock.post("*", (url, options) => { expect(url).toEqual( @@ -48,7 +48,9 @@ describe("create-org-notification", () => { expect(options.body).toContain(encodeParam("f", "json")); expect(options.body).toContain(encodeParam("subject", "Attention")); expect(options.body).toContain(encodeParam("message", "This is a test")); - expect(options.body).toContain(encodeParam("notificationChannelType", "email")); + expect(options.body).toContain( + encodeParam("notificationChannelType", "email") + ); expect(options.body).toContain( encodeParam("users", requests.shift().join(",")) ); @@ -61,29 +63,29 @@ describe("create-org-notification", () => { subject: "Attention", message: "This is a test", notificationChannelType: "email", - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; createOrgNotification(params) - .then(result => { + .then((result) => { expect(requests.length).toEqual(0); expect(responses.length).toEqual(0); expect(result.success).toEqual(true); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should return request failure", done => { + it("should return request failure", (done) => { const responses = [ { success: true }, { error: { code: 400, messageCode: "ORG_9001", - message: "error message for creating org notification" - } + message: "error message for creating org notification", + }, }, ]; @@ -94,11 +96,11 @@ describe("create-org-notification", () => { subject: "Attention", message: "This is a test", notificationChannelType: "email", - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; createOrgNotification(params) - .then(result => { + .then((result) => { expect(responses.length).toEqual(0); expect(result.success).toEqual(false); @@ -117,26 +119,26 @@ describe("create-org-notification", () => { expect(errorAOptions.params.users).toEqual(createUsernames(25, 30)); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); - it("should not send any request for zero-length username array", done => { + it("should not send any request for zero-length username array", (done) => { const params: ICreateOrgNotificationOptions = { message: "This won't get sent", subject: "Attention", notificationChannelType: "email", users: [], - authentication: MOCK_AUTH + authentication: MOCK_AUTH, }; - + fetchMock.post("*", () => 200); createOrgNotification(params) - .then(result => { + .then((result) => { expect(fetchMock.called()).toEqual(false); expect(result.success).toEqual(true); expect(result.errors).toBeUndefined(); done(); }) - .catch(error => fail(error)); + .catch((error) => fail(error)); }); -}); \ No newline at end of file +});