Files
outline/server/commands/starCreator.test.ts
Apoorv Mishra 7e61a519f1 Type server models (#6326)
* fix: type server models

* fix: make ParanoidModel generic

* fix: ApiKey

* fix: Attachment

* fix: AuthenticationProvider

* fix: Backlink

* fix: Collection

* fix: Comment

* fix: Document

* fix: FileOperation

* fix: Group

* fix: GroupPermission

* fix: GroupUser

* fix: Integration

* fix: IntegrationAuthentication

* fix: Notification

* fix: Pin

* fix: Revision

* fix: SearchQuery

* fix: Share

* fix: Star

* fix: Subscription

* fix: TypeError

* fix: Imports

* fix: Team

* fix: TeamDomain

* fix: User

* fix: UserAuthentication

* fix: UserPermission

* fix: View

* fix: WebhookDelivery

* fix: WebhookSubscription

* Remove type duplication

---------

Co-authored-by: Tom Moor <tom.moor@gmail.com>
2024-01-12 22:33:05 +05:30

68 lines
1.7 KiB
TypeScript

import { Star, Event } from "@server/models";
import { sequelize } from "@server/storage/database";
import { buildDocument, buildUser } from "@server/test/factories";
import starCreator from "./starCreator";
describe("starCreator", () => {
const ip = "127.0.0.1";
it("should create star", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const star = await sequelize.transaction(async (transaction) =>
starCreator({
documentId: document.id,
user,
ip,
transaction,
})
);
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(star.documentId).toEqual(document.id);
expect(star.userId).toEqual(user.id);
expect(star.index).toEqual("P");
expect(event!.name).toEqual("stars.create");
expect(event!.modelId).toEqual(star.id);
});
it("should not record event if star is existing", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
await Star.create({
documentId: document.id,
userId: user.id,
index: "P",
});
const star = await sequelize.transaction(async (transaction) =>
starCreator({
documentId: document.id,
user,
ip,
transaction,
})
);
const events = await Event.count({
where: {
teamId: user.teamId,
},
});
expect(star.documentId).toEqual(document.id);
expect(star.userId).toEqual(user.id);
expect(star.index).toEqual("P");
expect(events).toEqual(0);
});
});