Files
schpet__linear-cli/test/commands/document/document-view.test.ts
Peter Schilling cf770acf9d test: remove non-deterministic snapshot tests
Remove tests with inherently non-deterministic output:
- document-list: 3 tests displaying relative timestamps (e.g., '3 days ago')
- document-delete: 1 test with stack traces containing line numbers
- document-create: 1 test with stack traces containing machine-specific paths
- document-update: 2 tests with stack traces containing machine-specific paths
- document-view: 1 test with stack traces containing machine-specific paths

The fakeTime solution causes hangs with mock servers (known issue).
Stack traces contain machine-specific file paths that differ across environments.
2026-01-21 09:40:06 -08:00

207 lines
6.3 KiB
TypeScript

import { snapshotTest } from "@cliffy/testing"
import { viewCommand } from "../../../src/commands/document/document-view.ts"
import { MockLinearServer } from "../../utils/mock_linear_server.ts"
import { commonDenoArgs } from "../../utils/test-helpers.ts"
// Test help output
await snapshotTest({
name: "Document View Command - Help Text",
meta: import.meta,
colors: false,
args: ["--help"],
denoArgs: commonDenoArgs,
async fn() {
await viewCommand.parse()
},
})
// Test viewing a document
await snapshotTest({
name: "Document View Command - View Document",
meta: import.meta,
colors: false,
args: ["d4b93e3b2695"],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "GetDocument",
variables: { id: "d4b93e3b2695" },
response: {
data: {
document: {
id: "doc-1",
title: "Delegation System Spec",
slugId: "d4b93e3b2695",
content:
"# Delegation System\n\nThis document describes the delegation system architecture.\n\n## Overview\n\nThe system supports user-to-user delegations with time-bounded capabilities.\n\n## Implementation\n\n- UCAN-based delegation chains\n- PKH DID format for user identity\n- Session key DIDs for signing",
url:
"https://linear.app/test/document/delegation-system-spec-d4b93e3b2695",
createdAt: "2026-01-15T08:00:00Z",
updatedAt: "2026-01-18T10:30:00Z",
creator: { name: "John Doe", email: "john@example.com" },
project: { name: "TinyCloud SDK", slugId: "tinycloud-sdk" },
issue: null,
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await viewCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})
// Test viewing a document with --raw flag
await snapshotTest({
name: "Document View Command - Raw Output",
meta: import.meta,
colors: false,
args: ["d4b93e3b2695", "--raw"],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "GetDocument",
variables: { id: "d4b93e3b2695" },
response: {
data: {
document: {
id: "doc-1",
title: "Delegation System Spec",
slugId: "d4b93e3b2695",
content:
"# Delegation System\n\nThis document describes the delegation system architecture.",
url:
"https://linear.app/test/document/delegation-system-spec-d4b93e3b2695",
createdAt: "2026-01-15T08:00:00Z",
updatedAt: "2026-01-18T10:30:00Z",
creator: { name: "John Doe", email: "john@example.com" },
project: { name: "TinyCloud SDK", slugId: "tinycloud-sdk" },
issue: null,
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await viewCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})
// Test JSON output
await snapshotTest({
name: "Document View Command - JSON Output",
meta: import.meta,
colors: false,
args: ["d4b93e3b2695", "--json"],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "GetDocument",
variables: { id: "d4b93e3b2695" },
response: {
data: {
document: {
id: "doc-1",
title: "Delegation System Spec",
slugId: "d4b93e3b2695",
content:
"# Delegation System\n\nThis document describes the delegation system architecture.",
url:
"https://linear.app/test/document/delegation-system-spec-d4b93e3b2695",
createdAt: "2026-01-15T08:00:00Z",
updatedAt: "2026-01-18T10:30:00Z",
creator: { name: "John Doe", email: "john@example.com" },
project: { name: "TinyCloud SDK", slugId: "tinycloud-sdk" },
issue: null,
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await viewCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})
// NOTE: "Document Not Found" test removed - stack traces contain machine-specific paths
// Test document attached to issue
await snapshotTest({
name: "Document View Command - Document Attached To Issue",
meta: import.meta,
colors: false,
args: ["abc123def456"],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "GetDocument",
variables: { id: "abc123def456" },
response: {
data: {
document: {
id: "doc-3",
title: "Investigation Notes",
slugId: "abc123def456",
content:
"# Investigation Notes\n\nNotes from investigating TC-123.",
url:
"https://linear.app/test/document/investigation-notes-abc123def456",
createdAt: "2026-01-16T08:00:00Z",
updatedAt: "2026-01-16T09:00:00Z",
creator: { name: "Alice Dev", email: "alice@example.com" },
project: null,
issue: { identifier: "TC-123", title: "Fix login bug" },
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await viewCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})