diff --git a/server/api/attachments.test.js b/server/api/attachments.test.js index a61105bc..bc28b48a 100644 --- a/server/api/attachments.test.js +++ b/server/api/attachments.test.js @@ -4,6 +4,7 @@ import app from "../app"; import { Attachment } from "../models"; import { buildUser, + buildAdmin, buildCollection, buildAttachment, buildDocument, @@ -62,7 +63,7 @@ describe("#attachments.delete", () => { }); it("should allow deleting an attachment without a document if admin", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const attachment = await buildAttachment({ teamId: user.teamId, }); @@ -79,7 +80,7 @@ describe("#attachments.delete", () => { }); it("should not allow deleting an attachment in another team", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const attachment = await buildAttachment(); attachment.documentId = null; diff --git a/server/api/collections.test.js b/server/api/collections.test.js index 2a4c816f..5eb2653d 100644 --- a/server/api/collections.test.js +++ b/server/api/collections.test.js @@ -4,6 +4,7 @@ import app from "../app"; import { Document, CollectionUser, CollectionGroup } from "../models"; import { buildUser, + buildAdmin, buildGroup, buildCollection, buildDocument, @@ -428,7 +429,7 @@ describe("#collections.add_user", () => { describe("#collections.add_group", () => { it("should add group to collection", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const collection = await buildCollection({ teamId: user.teamId, userId: user.id, @@ -491,7 +492,7 @@ describe("#collections.add_group", () => { describe("#collections.remove_group", () => { it("should remove group from collection", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const collection = await buildCollection({ teamId: user.teamId, userId: user.id, diff --git a/server/api/groups.test.js b/server/api/groups.test.js index 52430efc..104dd666 100644 --- a/server/api/groups.test.js +++ b/server/api/groups.test.js @@ -2,7 +2,7 @@ import TestServer from "fetch-test-server"; import app from "../app"; import { Event } from "../models"; -import { buildUser, buildGroup } from "../test/factories"; +import { buildUser, buildAdmin, buildGroup } from "../test/factories"; import { flushdb } from "../test/support"; const server = new TestServer(app.callback()); @@ -13,7 +13,7 @@ afterAll(() => server.close()); describe("#groups.create", () => { it("should create a group", async () => { const name = "hello I am a group"; - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const res = await server.post("/api/groups.create", { body: { token: user.getJwtToken(), name }, @@ -49,7 +49,7 @@ describe("#groups.update", () => { it("should require authorization", async () => { const group = await buildGroup(); - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const res = await server.post("/api/groups.update", { body: { token: user.getJwtToken(), id: group.id, name: "Test" }, @@ -61,7 +61,7 @@ describe("#groups.update", () => { let user, group; beforeEach(async () => { - user = await buildUser({ isAdmin: true }); + user = await buildAdmin(); group = await buildGroup({ teamId: user.teamId }); }); @@ -175,7 +175,7 @@ describe("#groups.list", () => { describe("#groups.info", () => { it("should return group if admin", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId }); const res = await server.post("/api/groups.info", { @@ -255,7 +255,7 @@ describe("#groups.delete", () => { it("should require authorization", async () => { const group = await buildGroup(); - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const res = await server.post("/api/groups.delete", { body: { token: user.getJwtToken(), id: group.id }, @@ -264,7 +264,7 @@ describe("#groups.delete", () => { }); it("allows admin to delete a group", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId }); const res = await server.post("/api/groups.delete", { @@ -344,7 +344,7 @@ describe("#groups.memberships", () => { describe("#groups.add_user", () => { it("should add user to group", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId, }); @@ -368,7 +368,7 @@ describe("#groups.add_user", () => { }); it("should require user in team", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId, }); @@ -412,7 +412,7 @@ describe("#groups.add_user", () => { describe("#groups.remove_user", () => { it("should remove user from group", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId, }); @@ -448,7 +448,7 @@ describe("#groups.remove_user", () => { }); it("should require user in team", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const group = await buildGroup({ teamId: user.teamId, }); diff --git a/server/api/users.test.js b/server/api/users.test.js index a0be7a8b..86710de9 100644 --- a/server/api/users.test.js +++ b/server/api/users.test.js @@ -2,7 +2,7 @@ import TestServer from "fetch-test-server"; import app from "../app"; -import { buildTeam, buildUser } from "../test/factories"; +import { buildTeam, buildAdmin, buildUser } from "../test/factories"; import { flushdb, seed } from "../test/support"; @@ -107,7 +107,7 @@ describe("#users.info", () => { describe("#users.invite", () => { it("should return sent invites", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const res = await server.post("/api/users.invite", { body: { token: user.getJwtToken(), @@ -146,7 +146,7 @@ describe("#users.delete", () => { }); it("should allow deleting last admin if only user", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const res = await server.post("/api/users.delete", { body: { token: user.getJwtToken(), confirmation: true }, }); @@ -154,7 +154,7 @@ describe("#users.delete", () => { }); it("should not allow deleting last admin if many users", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); await buildUser({ teamId: user.teamId, isAdmin: false }); const res = await server.post("/api/users.delete", { @@ -172,7 +172,7 @@ describe("#users.delete", () => { }); it("should allow deleting pending user account with admin", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const pending = await buildUser({ teamId: user.teamId, lastActiveAt: null, @@ -184,7 +184,7 @@ describe("#users.delete", () => { }); it("should not allow deleting another user account", async () => { - const user = await buildUser({ isAdmin: true }); + const user = await buildAdmin(); const user2 = await buildUser({ teamId: user.teamId }); const res = await server.post("/api/users.delete", { body: { token: user.getJwtToken(), id: user2.id, confirmation: true }, @@ -265,7 +265,7 @@ describe("#users.demote", () => { }); it("should not demote admins if only one available", async () => { - const admin = await buildUser({ isAdmin: true }); + const admin = await buildAdmin(); const res = await server.post("/api/users.demote", { body: { @@ -308,7 +308,7 @@ describe("#users.suspend", () => { }); it("should not allow suspending the user themselves", async () => { - const admin = await buildUser({ isAdmin: true }); + const admin = await buildAdmin(); const res = await server.post("/api/users.suspend", { body: { token: admin.getJwtToken(), diff --git a/server/commands/userSuspender.test.js b/server/commands/userSuspender.test.js index 751712b3..c4038ed7 100644 --- a/server/commands/userSuspender.test.js +++ b/server/commands/userSuspender.test.js @@ -1,6 +1,6 @@ /* eslint-disable flowtype/require-valid-file-annotation */ import { GroupUser } from "../models"; -import { buildGroup, buildUser } from "../test/factories"; +import { buildGroup, buildAdmin, buildUser } from "../test/factories"; import { flushdb } from "../test/support"; import userSuspender from "./userSuspender"; @@ -27,7 +27,7 @@ describe("userSuspender", () => { }); it("should suspend the user", async () => { - const admin = await buildUser({ isAdmin: true }); + const admin = await buildAdmin(); const user = await buildUser({ teamId: admin.teamId }); await userSuspender({ actorId: admin.id, @@ -39,7 +39,7 @@ describe("userSuspender", () => { }); it("should remove group memberships", async () => { - const admin = await buildUser({ isAdmin: true }); + const admin = await buildAdmin(); const user = await buildUser({ teamId: admin.teamId }); const group = await buildGroup({ teamId: user.teamId }); diff --git a/yarn.lock b/yarn.lock index 1e33be29..0e862918 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10940,11 +10940,6 @@ rechoir@^0.6.2: dependencies: resolve "^1.1.6" -redis-commands@1.6.0: - version "1.6.0" - resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.6.0.tgz#36d4ca42ae9ed29815cdb30ad9f97982eba1ce23" - integrity sha512-2jnZ0IkjZxvguITjFTrGiLyzQZcTvaw8DAaCXxZq/dsHXz7KfMQ3OUJy7Tz9vnRtZRVz6VRCPDvruvU8Ts44wQ== - redis-commands@1.7.0, redis-commands@^1.5.0: version "1.7.0" resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89" @@ -12105,7 +12100,7 @@ stack-utils@^2.0.2: dependencies: escape-string-regexp "^2.0.0" -standard-as-callback@^2.0.1, standard-as-callback@^2.1.0: +standard-as-callback@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/standard-as-callback/-/standard-as-callback-2.1.0.tgz#8953fc05359868a77b5b9739a665c5977bb7df45" integrity sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==