mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
Add tests
This commit is contained in:
1 parent
f57b066b25
commit
01b1ff65ff
1 file changed
+75
-9
@@ -1,8 +1,13 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import TestServer from "fetch-test-server";
|
||||
import { Event } from "../../models";
|
||||
import { CollectionGroup, Event } from "../../models";
|
||||
import webService from "../../services/web";
|
||||
import { buildUser, buildAdmin, buildGroup } from "../../test/factories";
|
||||
import {
|
||||
buildUser,
|
||||
buildAdmin,
|
||||
buildGroup,
|
||||
buildCollection,
|
||||
} from "../../test/factories";
|
||||
import { flushdb } from "../../test/support";
|
||||
const app = webService();
|
||||
const server = new TestServer(app.callback());
|
||||
@@ -59,17 +64,17 @@ describe("#groups.update", () => {
|
||||
});
|
||||
|
||||
describe("when user is admin", () => {
|
||||
let user, group;
|
||||
let admin, group;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await buildAdmin();
|
||||
group = await buildGroup({ teamId: user.teamId });
|
||||
admin = await buildAdmin();
|
||||
group = await buildGroup({ teamId: admin.teamId });
|
||||
});
|
||||
|
||||
it("allows admin to edit a group", async () => {
|
||||
const res = await server.post("/api/groups.update", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
token: admin.getJwtToken(),
|
||||
id: group.id,
|
||||
name: "Test",
|
||||
isPrivate: false,
|
||||
@@ -85,9 +90,70 @@ describe("#groups.update", () => {
|
||||
expect(body.data.isPrivate).toBe(false);
|
||||
});
|
||||
|
||||
it("make groups readonly in collection if the visibility of group changes to private", async () => {
|
||||
const user = await buildUser({ teamId: admin.teamId });
|
||||
|
||||
const privateCollection = await buildCollection({
|
||||
teamId: admin.teamId,
|
||||
createdById: user.id,
|
||||
permission: null,
|
||||
});
|
||||
|
||||
const response1 = await server.post("/api/groups.add_user", {
|
||||
body: {
|
||||
token: admin.getJwtToken(),
|
||||
userId: admin.id,
|
||||
id: group.id,
|
||||
},
|
||||
});
|
||||
|
||||
const response2 = await server.post("/api/groups.update", {
|
||||
body: {
|
||||
token: admin.getJwtToken(),
|
||||
name: group.name,
|
||||
id: group.id,
|
||||
isPrivate: false,
|
||||
},
|
||||
});
|
||||
|
||||
const response3 = await server.post("/api/collections.add_group", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
groupId: group.id,
|
||||
id: privateCollection.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response1.status).toBe(200);
|
||||
expect(response2.status).toBe(200);
|
||||
expect(response3.status).toBe(200);
|
||||
|
||||
const res = await server.post("/api/groups.update", {
|
||||
body: {
|
||||
token: admin.getJwtToken(),
|
||||
name: group.name,
|
||||
id: group.id,
|
||||
isPrivate: true,
|
||||
},
|
||||
});
|
||||
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.isPrivate).toBe(true);
|
||||
|
||||
const collectionGroups = await CollectionGroup.findAll({
|
||||
where: {
|
||||
groupId: group.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(collectionGroups.length).toBe(1);
|
||||
expect(collectionGroups[0].permission).toBe("read");
|
||||
});
|
||||
|
||||
it("does not create an event if the update is a noop", async () => {
|
||||
const res = await server.post("/api/groups.update", {
|
||||
body: { token: user.getJwtToken(), id: group.id, name: group.name },
|
||||
body: { token: admin.getJwtToken(), id: group.id, name: group.name },
|
||||
});
|
||||
|
||||
const events = await Event.findAll();
|
||||
@@ -100,13 +166,13 @@ describe("#groups.update", () => {
|
||||
|
||||
it("fails with validation error when name already taken", async () => {
|
||||
await buildGroup({
|
||||
teamId: user.teamId,
|
||||
teamId: admin.teamId,
|
||||
name: "test",
|
||||
});
|
||||
|
||||
const res = await server.post("/api/groups.update", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
token: admin.getJwtToken(),
|
||||
id: group.id,
|
||||
name: "TEST",
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user