buildUser -> buildAdmin
This commit is contained in:
parent
9f6ba798c8
commit
059fca27b3
@ -4,6 +4,7 @@ import app from "../app";
|
|||||||
import { Attachment } from "../models";
|
import { Attachment } from "../models";
|
||||||
import {
|
import {
|
||||||
buildUser,
|
buildUser,
|
||||||
|
buildAdmin,
|
||||||
buildCollection,
|
buildCollection,
|
||||||
buildAttachment,
|
buildAttachment,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
@ -62,7 +63,7 @@ describe("#attachments.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should allow deleting an attachment without a document if admin", async () => {
|
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({
|
const attachment = await buildAttachment({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
@ -79,7 +80,7 @@ describe("#attachments.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow deleting an attachment in another team", async () => {
|
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();
|
const attachment = await buildAttachment();
|
||||||
|
|
||||||
attachment.documentId = null;
|
attachment.documentId = null;
|
||||||
|
@ -4,6 +4,7 @@ import app from "../app";
|
|||||||
import { Document, CollectionUser, CollectionGroup } from "../models";
|
import { Document, CollectionUser, CollectionGroup } from "../models";
|
||||||
import {
|
import {
|
||||||
buildUser,
|
buildUser,
|
||||||
|
buildAdmin,
|
||||||
buildGroup,
|
buildGroup,
|
||||||
buildCollection,
|
buildCollection,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
@ -428,7 +429,7 @@ describe("#collections.add_user", () => {
|
|||||||
|
|
||||||
describe("#collections.add_group", () => {
|
describe("#collections.add_group", () => {
|
||||||
it("should add group to collection", async () => {
|
it("should add group to collection", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const collection = await buildCollection({
|
const collection = await buildCollection({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
@ -491,7 +492,7 @@ describe("#collections.add_group", () => {
|
|||||||
|
|
||||||
describe("#collections.remove_group", () => {
|
describe("#collections.remove_group", () => {
|
||||||
it("should remove group from collection", async () => {
|
it("should remove group from collection", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const collection = await buildCollection({
|
const collection = await buildCollection({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import TestServer from "fetch-test-server";
|
import TestServer from "fetch-test-server";
|
||||||
import app from "../app";
|
import app from "../app";
|
||||||
import { Event } from "../models";
|
import { Event } from "../models";
|
||||||
import { buildUser, buildGroup } from "../test/factories";
|
import { buildUser, buildAdmin, buildGroup } from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
|
|
||||||
const server = new TestServer(app.callback());
|
const server = new TestServer(app.callback());
|
||||||
@ -13,7 +13,7 @@ afterAll(() => server.close());
|
|||||||
describe("#groups.create", () => {
|
describe("#groups.create", () => {
|
||||||
it("should create a group", async () => {
|
it("should create a group", async () => {
|
||||||
const name = "hello I am a group";
|
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", {
|
const res = await server.post("/api/groups.create", {
|
||||||
body: { token: user.getJwtToken(), name },
|
body: { token: user.getJwtToken(), name },
|
||||||
@ -49,7 +49,7 @@ describe("#groups.update", () => {
|
|||||||
|
|
||||||
it("should require authorization", async () => {
|
it("should require authorization", async () => {
|
||||||
const group = await buildGroup();
|
const group = await buildGroup();
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
|
|
||||||
const res = await server.post("/api/groups.update", {
|
const res = await server.post("/api/groups.update", {
|
||||||
body: { token: user.getJwtToken(), id: group.id, name: "Test" },
|
body: { token: user.getJwtToken(), id: group.id, name: "Test" },
|
||||||
@ -61,7 +61,7 @@ describe("#groups.update", () => {
|
|||||||
let user, group;
|
let user, group;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
user = await buildUser({ isAdmin: true });
|
user = await buildAdmin();
|
||||||
group = await buildGroup({ teamId: user.teamId });
|
group = await buildGroup({ teamId: user.teamId });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ describe("#groups.list", () => {
|
|||||||
|
|
||||||
describe("#groups.info", () => {
|
describe("#groups.info", () => {
|
||||||
it("should return group if admin", async () => {
|
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 group = await buildGroup({ teamId: user.teamId });
|
||||||
|
|
||||||
const res = await server.post("/api/groups.info", {
|
const res = await server.post("/api/groups.info", {
|
||||||
@ -255,7 +255,7 @@ describe("#groups.delete", () => {
|
|||||||
|
|
||||||
it("should require authorization", async () => {
|
it("should require authorization", async () => {
|
||||||
const group = await buildGroup();
|
const group = await buildGroup();
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
|
|
||||||
const res = await server.post("/api/groups.delete", {
|
const res = await server.post("/api/groups.delete", {
|
||||||
body: { token: user.getJwtToken(), id: group.id },
|
body: { token: user.getJwtToken(), id: group.id },
|
||||||
@ -264,7 +264,7 @@ describe("#groups.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("allows admin to delete a group", async () => {
|
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 group = await buildGroup({ teamId: user.teamId });
|
||||||
|
|
||||||
const res = await server.post("/api/groups.delete", {
|
const res = await server.post("/api/groups.delete", {
|
||||||
@ -344,7 +344,7 @@ describe("#groups.memberships", () => {
|
|||||||
|
|
||||||
describe("#groups.add_user", () => {
|
describe("#groups.add_user", () => {
|
||||||
it("should add user to group", async () => {
|
it("should add user to group", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const group = await buildGroup({
|
const group = await buildGroup({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
@ -368,7 +368,7 @@ describe("#groups.add_user", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should require user in team", async () => {
|
it("should require user in team", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const group = await buildGroup({
|
const group = await buildGroup({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
@ -412,7 +412,7 @@ describe("#groups.add_user", () => {
|
|||||||
|
|
||||||
describe("#groups.remove_user", () => {
|
describe("#groups.remove_user", () => {
|
||||||
it("should remove user from group", async () => {
|
it("should remove user from group", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const group = await buildGroup({
|
const group = await buildGroup({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
@ -448,7 +448,7 @@ describe("#groups.remove_user", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should require user in team", async () => {
|
it("should require user in team", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const group = await buildGroup({
|
const group = await buildGroup({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import TestServer from "fetch-test-server";
|
import TestServer from "fetch-test-server";
|
||||||
import app from "../app";
|
import app from "../app";
|
||||||
|
|
||||||
import { buildTeam, buildUser } from "../test/factories";
|
import { buildTeam, buildAdmin, buildUser } from "../test/factories";
|
||||||
|
|
||||||
import { flushdb, seed } from "../test/support";
|
import { flushdb, seed } from "../test/support";
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ describe("#users.info", () => {
|
|||||||
|
|
||||||
describe("#users.invite", () => {
|
describe("#users.invite", () => {
|
||||||
it("should return sent invites", async () => {
|
it("should return sent invites", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const res = await server.post("/api/users.invite", {
|
const res = await server.post("/api/users.invite", {
|
||||||
body: {
|
body: {
|
||||||
token: user.getJwtToken(),
|
token: user.getJwtToken(),
|
||||||
@ -146,7 +146,7 @@ describe("#users.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should allow deleting last admin if only user", async () => {
|
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", {
|
const res = await server.post("/api/users.delete", {
|
||||||
body: { token: user.getJwtToken(), confirmation: true },
|
body: { token: user.getJwtToken(), confirmation: true },
|
||||||
});
|
});
|
||||||
@ -154,7 +154,7 @@ describe("#users.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow deleting last admin if many users", async () => {
|
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 });
|
await buildUser({ teamId: user.teamId, isAdmin: false });
|
||||||
|
|
||||||
const res = await server.post("/api/users.delete", {
|
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 () => {
|
it("should allow deleting pending user account with admin", async () => {
|
||||||
const user = await buildUser({ isAdmin: true });
|
const user = await buildAdmin();
|
||||||
const pending = await buildUser({
|
const pending = await buildUser({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
lastActiveAt: null,
|
lastActiveAt: null,
|
||||||
@ -184,7 +184,7 @@ describe("#users.delete", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow deleting another user account", async () => {
|
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 user2 = await buildUser({ teamId: user.teamId });
|
||||||
const res = await server.post("/api/users.delete", {
|
const res = await server.post("/api/users.delete", {
|
||||||
body: { token: user.getJwtToken(), id: user2.id, confirmation: true },
|
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 () => {
|
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", {
|
const res = await server.post("/api/users.demote", {
|
||||||
body: {
|
body: {
|
||||||
@ -308,7 +308,7 @@ describe("#users.suspend", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow suspending the user themselves", async () => {
|
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", {
|
const res = await server.post("/api/users.suspend", {
|
||||||
body: {
|
body: {
|
||||||
token: admin.getJwtToken(),
|
token: admin.getJwtToken(),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||||
import { GroupUser } from "../models";
|
import { GroupUser } from "../models";
|
||||||
import { buildGroup, buildUser } from "../test/factories";
|
import { buildGroup, buildAdmin, buildUser } from "../test/factories";
|
||||||
import { flushdb } from "../test/support";
|
import { flushdb } from "../test/support";
|
||||||
import userSuspender from "./userSuspender";
|
import userSuspender from "./userSuspender";
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ describe("userSuspender", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should suspend the user", async () => {
|
it("should suspend the user", async () => {
|
||||||
const admin = await buildUser({ isAdmin: true });
|
const admin = await buildAdmin();
|
||||||
const user = await buildUser({ teamId: admin.teamId });
|
const user = await buildUser({ teamId: admin.teamId });
|
||||||
await userSuspender({
|
await userSuspender({
|
||||||
actorId: admin.id,
|
actorId: admin.id,
|
||||||
@ -39,7 +39,7 @@ describe("userSuspender", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should remove group memberships", async () => {
|
it("should remove group memberships", async () => {
|
||||||
const admin = await buildUser({ isAdmin: true });
|
const admin = await buildAdmin();
|
||||||
const user = await buildUser({ teamId: admin.teamId });
|
const user = await buildUser({ teamId: admin.teamId });
|
||||||
const group = await buildGroup({ teamId: user.teamId });
|
const group = await buildGroup({ teamId: user.teamId });
|
||||||
|
|
||||||
|
@ -10940,11 +10940,6 @@ rechoir@^0.6.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
resolve "^1.1.6"
|
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:
|
redis-commands@1.7.0, redis-commands@^1.5.0:
|
||||||
version "1.7.0"
|
version "1.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89"
|
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89"
|
||||||
@ -12105,7 +12100,7 @@ stack-utils@^2.0.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
escape-string-regexp "^2.0.0"
|
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"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/standard-as-callback/-/standard-as-callback-2.1.0.tgz#8953fc05359868a77b5b9739a665c5977bb7df45"
|
resolved "https://registry.yarnpkg.com/standard-as-callback/-/standard-as-callback-2.1.0.tgz#8953fc05359868a77b5b9739a665c5977bb7df45"
|
||||||
integrity sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==
|
integrity sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==
|
||||||
|
Reference in New Issue
Block a user