-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshow.test.ts
More file actions
91 lines (78 loc) · 2.4 KB
/
Copy pathshow.test.ts
File metadata and controls
91 lines (78 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { runCommand } from "@oclif/test";
import { MittwaldAPIV2 } from "@mittwald/api-client";
import nock from "nock";
import { expect } from "@jest/globals";
type Conversation = MittwaldAPIV2.Components.Schemas.ConversationConversation;
type Message = MittwaldAPIV2.Components.Schemas.ConversationMessage;
type StatusUpdate = MittwaldAPIV2.Components.Schemas.ConversationStatusUpdate;
describe("conversation:show", () => {
const conversationId = "186f8f22-aa0f-42bf-909d-757cb9d27b04";
const userId = "6dbd84b5-74e0-43ed-8a81-b0b8a0405a47";
const messageId = "10a59409-ff2d-478e-b07f-72c8f9f5b63f";
const now = new Date();
const user = {
userId,
clearName: "John Doe",
};
let originalEnv: NodeJS.ProcessEnv;
beforeEach(() => {
originalEnv = { ...process.env };
process.env["MITTWALD_API_TOKEN"] = "foo";
nock.disableNetConnect();
});
afterEach(() => {
process.env = originalEnv;
nock.cleanAll();
});
it("should test", () => {
expect(true).toBeTruthy();
});
it("shows a conversation and its messages", async () => {
const scope = nock("https://api.mittwald.de")
.get(`/v2/conversations/${conversationId}`)
.reply(200, {
conversationId,
shortId: "CONV-ID",
createdAt: now.toJSON(),
title: "Test conversation",
status: "open",
visibility: "shared",
mainUser: user,
} satisfies Conversation)
.get(`/v2/conversations/${conversationId}/messages`)
.reply(200, [
{
conversationId,
type: "STATUS_UPDATE",
createdAt: now.toJSON(),
meta: { user },
messageContent: "CONVERSATION_CREATED",
},
{
messageId,
conversationId,
type: "MESSAGE",
createdAt: now.toJSON(),
createdBy: user,
messageContent: "Hello, World!",
},
{
conversationId,
type: "STATUS_UPDATE",
createdAt: now.toJSON(),
meta: { user },
messageContent: "STATUS_CLOSED",
},
] satisfies Array<Message | StatusUpdate>);
console.log("foo");
const { stdout, stderr, error } = await runCommand([
"conversation:show",
conversationId,
]);
console.log("foo");
setTimeout(() => scope.done(), 5000);
expect(stdout).toEqual("");
expect(stderr).toEqual("");
expect(error).toBeUndefined();
});
});