@@ -1,4 +1,4 @@
|
||||
import { Document } from "@server/models";
|
||||
import Document from "@server/models/Document";
|
||||
import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
@@ -10,6 +10,7 @@ import slugify from "@server/utils/slugify";
|
||||
|
||||
beforeEach(() => flushdb());
|
||||
beforeEach(jest.resetAllMocks);
|
||||
|
||||
describe("#getSummary", () => {
|
||||
test("should strip markdown", async () => {
|
||||
const document = await buildDocument({
|
||||
@@ -23,7 +24,7 @@ paragraph 2`,
|
||||
|
||||
test("should strip title when no version", async () => {
|
||||
const document = await buildDocument({
|
||||
version: null,
|
||||
version: 0,
|
||||
text: `# Heading
|
||||
|
||||
*paragraph*`,
|
||||
@@ -31,6 +32,7 @@ paragraph 2`,
|
||||
expect(document.getSummary()).toBe("paragraph");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#migrateVersion", () => {
|
||||
test("should maintain empty paragraph under headings", async () => {
|
||||
const document = await buildDocument({
|
||||
@@ -155,6 +157,7 @@ paragraph`);
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#searchForTeam", () => {
|
||||
test("should return search results from public collections", async () => {
|
||||
const team = await buildTeam();
|
||||
@@ -168,7 +171,7 @@ describe("#searchForTeam", () => {
|
||||
});
|
||||
const { results } = await Document.searchForTeam(team, "test");
|
||||
expect(results.length).toBe(1);
|
||||
expect(results[0].document.id).toBe(document.id);
|
||||
expect(results[0].document?.id).toBe(document.id);
|
||||
});
|
||||
|
||||
test("should not return search results from private collections", async () => {
|
||||
@@ -252,6 +255,7 @@ describe("#searchForTeam", () => {
|
||||
expect(totalCount).toBe("0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#searchForUser", () => {
|
||||
test("should return search results from collections", async () => {
|
||||
const team = await buildTeam();
|
||||
@@ -270,7 +274,7 @@ describe("#searchForUser", () => {
|
||||
});
|
||||
const { results } = await Document.searchForUser(user, "test");
|
||||
expect(results.length).toBe(1);
|
||||
expect(results[0].document.id).toBe(document.id);
|
||||
expect(results[0].document?.id).toBe(document.id);
|
||||
});
|
||||
|
||||
test("should handle no collections", async () => {
|
||||
@@ -352,44 +356,47 @@ describe("#searchForUser", () => {
|
||||
expect(totalCount).toBe("0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#delete", () => {
|
||||
test("should soft delete and set last modified", async () => {
|
||||
let document = await buildDocument();
|
||||
const document = await buildDocument();
|
||||
const user = await buildUser();
|
||||
await document.delete(user.id);
|
||||
document = await Document.findByPk(document.id, {
|
||||
|
||||
const newDocument = await Document.findByPk(document.id, {
|
||||
paranoid: false,
|
||||
});
|
||||
expect(document.lastModifiedById).toBe(user.id);
|
||||
expect(document.deletedAt).toBeTruthy();
|
||||
expect(newDocument?.lastModifiedById).toBe(user.id);
|
||||
expect(newDocument?.deletedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should soft delete templates", async () => {
|
||||
let document = await buildDocument({
|
||||
const document = await buildDocument({
|
||||
template: true,
|
||||
});
|
||||
const user = await buildUser();
|
||||
await document.delete(user.id);
|
||||
document = await Document.findByPk(document.id, {
|
||||
const newDocument = await Document.findByPk(document.id, {
|
||||
paranoid: false,
|
||||
});
|
||||
expect(document.lastModifiedById).toBe(user.id);
|
||||
expect(document.deletedAt).toBeTruthy();
|
||||
expect(newDocument?.lastModifiedById).toBe(user.id);
|
||||
expect(newDocument?.deletedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should soft delete archived", async () => {
|
||||
let document = await buildDocument({
|
||||
const document = await buildDocument({
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const user = await buildUser();
|
||||
await document.delete(user.id);
|
||||
document = await Document.findByPk(document.id, {
|
||||
const newDocument = await Document.findByPk(document.id, {
|
||||
paranoid: false,
|
||||
});
|
||||
expect(document.lastModifiedById).toBe(user.id);
|
||||
expect(document.deletedAt).toBeTruthy();
|
||||
expect(newDocument?.lastModifiedById).toBe(user.id);
|
||||
expect(newDocument?.deletedAt).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#save", () => {
|
||||
test("should have empty previousTitles by default", async () => {
|
||||
const document = await buildDocument();
|
||||
@@ -414,14 +421,16 @@ describe("#save", () => {
|
||||
expect(document.previousTitles.length).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#findByPk", () => {
|
||||
test("should return document when urlId is correct", async () => {
|
||||
const { document } = await seed();
|
||||
const id = `${slugify(document.title)}-${document.urlId}`;
|
||||
const response = await Document.findByPk(id);
|
||||
expect(response.id).toBe(document.id);
|
||||
expect(response?.id).toBe(document.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tasks", () => {
|
||||
test("should consider all the possible checkTtems", async () => {
|
||||
const document = await buildDocument({
|
||||
|
||||
Reference in New Issue
Block a user