test: 补全消息唯一约束覆盖
This commit is contained in:
@@ -200,6 +200,70 @@ describe("database authority constraints", () => {
|
||||
expect(message.seq).toBe(1n);
|
||||
});
|
||||
|
||||
it("rejects duplicate message client ids within a conversation", async () => {
|
||||
const author = await createAccount("message-client-id");
|
||||
const bottle = await createBottle(author.id, "message-client-id");
|
||||
const conversation = await prisma.conversation.create({
|
||||
data: { sourceBottleId: bottle.id },
|
||||
});
|
||||
|
||||
await expect(
|
||||
prisma.message.create({
|
||||
data: {
|
||||
conversationId: conversation.id,
|
||||
senderId: author.id,
|
||||
clientMsgId: "duplicate-client-id",
|
||||
seq: 1n,
|
||||
contentText: "first",
|
||||
},
|
||||
}),
|
||||
).resolves.toMatchObject({ clientMsgId: "duplicate-client-id", seq: 1n });
|
||||
|
||||
await expectUniqueViolation(
|
||||
prisma.message.create({
|
||||
data: {
|
||||
conversationId: conversation.id,
|
||||
senderId: author.id,
|
||||
clientMsgId: "duplicate-client-id",
|
||||
seq: 2n,
|
||||
contentText: "second",
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects duplicate message sequences within a conversation", async () => {
|
||||
const author = await createAccount("message-seq");
|
||||
const bottle = await createBottle(author.id, "message-seq");
|
||||
const conversation = await prisma.conversation.create({
|
||||
data: { sourceBottleId: bottle.id },
|
||||
});
|
||||
|
||||
await expect(
|
||||
prisma.message.create({
|
||||
data: {
|
||||
conversationId: conversation.id,
|
||||
senderId: author.id,
|
||||
clientMsgId: "first-client-id",
|
||||
seq: 1n,
|
||||
contentText: "first",
|
||||
},
|
||||
}),
|
||||
).resolves.toMatchObject({ clientMsgId: "first-client-id", seq: 1n });
|
||||
|
||||
await expectUniqueViolation(
|
||||
prisma.message.create({
|
||||
data: {
|
||||
conversationId: conversation.id,
|
||||
senderId: author.id,
|
||||
clientMsgId: "second-client-id",
|
||||
seq: 1n,
|
||||
contentText: "second",
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects self-blocks", async () => {
|
||||
const account = await createAccount("self-block");
|
||||
await expectConstraintViolation(
|
||||
|
||||
Reference in New Issue
Block a user