-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from mittwald/task/refact-conversation-show
Add example for command unit tests
- Loading branch information
Showing
84 changed files
with
984 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ dist/ | |
dist-cjs/ | ||
coverage/ | ||
*.tsbuildinfo | ||
.nyc_output | ||
|
||
# Other | ||
*.log | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+34.1 KB
.yarn/cache/@cspotcode-source-map-support-npm-0.8.1-964f2de99d-5718f26708.zip
Binary file not shown.
Binary file added
BIN
+17.5 KB
.yarn/cache/@jridgewell-resolve-uri-npm-3.1.2-5bc4245992-83b85f72c5.zip
Binary file not shown.
Binary file added
BIN
+14.7 KB
.yarn/cache/@jridgewell-sourcemap-codec-npm-1.4.15-a055fb62cf-b881c7e503.zip
Binary file not shown.
Binary file added
BIN
+27.5 KB
.yarn/cache/@jridgewell-trace-mapping-npm-0.3.9-91625cd7fb-d89597752f.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+19.3 KB
.yarn/cache/@sinonjs-fake-timers-npm-10.3.0-7417f876b4-614d30cb4d.zip
Binary file not shown.
Binary file added
BIN
+19.9 KB
.yarn/cache/@sinonjs-fake-timers-npm-11.2.2-eb695fcf3c-68c29b0e18.zip
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+210 KB
.yarn/cache/@sinonjs-text-encoding-npm-0.7.2-ab9862ba52-fe690002a3.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+5.38 KB
.yarn/cache/@types-sinonjs__fake-timers-npm-8.1.5-c35b400174-7e3c08f6c1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { expect, test } from "@oclif/test"; | ||
import type { MittwaldAPIV2 } from "@mittwald/api-client"; | ||
|
||
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", | ||
}; | ||
|
||
test | ||
.nock("https://api.mittwald.de", (api) => { | ||
api | ||
.persist() | ||
.get(`/v2/conversations/${conversationId}`) | ||
.reply(200, { | ||
conversationId, | ||
shortId: "CONV-ID", | ||
createdAt: now.toJSON(), | ||
title: "Test conversation", | ||
status: "open", | ||
visibility: "shared", | ||
mainUser: user, | ||
} satisfies Conversation); | ||
|
||
api.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>); | ||
}) | ||
.env({ MITTWALD_API_TOKEN: "foo" }) | ||
.stdout() | ||
.command(["conversation show", conversationId]) | ||
.it("shows a conversation and its messages", (ctx) => { | ||
expect(ctx.stdout.trim()).to.equal(`Conversation metadata | ||
───────────────────── | ||
Title Test conversation | ||
ID CONV-ID | ||
Opened less than a minute ago by Unknown User | ||
Status open | ||
Messages | ||
──────── | ||
CREATED, less than a minute ago | ||
John Doe, less than a minute ago | ||
Hello, World! | ||
CLOSED, less than a minute ago`); | ||
}); | ||
}); |
Oops, something went wrong.