bingocode 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -2
- package/.github/FUNDING.yml +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -44
- package/.github/ISSUE_TEMPLATE/config.yml +0 -1
- package/.github/ISSUE_TEMPLATE/question.md +0 -40
- package/.github/workflows/build-desktop-dev.yml +0 -210
- package/.github/workflows/deploy-docs.yml +0 -59
- package/.github/workflows/release-desktop.yml +0 -162
- package/.spine/user.yaml +0 -5
- package/.spine/workspace.yaml +0 -1
- package/adapters/common/__tests__/chat-queue.test.ts +0 -61
- package/adapters/common/__tests__/format.test.ts +0 -148
- package/adapters/common/__tests__/http-client.test.ts +0 -105
- package/adapters/common/__tests__/message-buffer.test.ts +0 -84
- package/adapters/common/__tests__/message-dedup.test.ts +0 -57
- package/adapters/common/__tests__/session-store.test.ts +0 -62
- package/adapters/common/__tests__/ws-bridge.test.ts +0 -177
- package/adapters/common/attachment/__tests__/attachment-limits.test.ts +0 -52
- package/adapters/common/attachment/__tests__/attachment-store.test.ts +0 -108
- package/adapters/common/attachment/__tests__/image-block-watcher.test.ts +0 -115
- package/adapters/feishu/__tests__/card-errors.test.ts +0 -194
- package/adapters/feishu/__tests__/cardkit.test.ts +0 -295
- package/adapters/feishu/__tests__/extract-payload.test.ts +0 -77
- package/adapters/feishu/__tests__/feishu.test.ts +0 -907
- package/adapters/feishu/__tests__/flush-controller.test.ts +0 -290
- package/adapters/feishu/__tests__/markdown-style.test.ts +0 -353
- package/adapters/feishu/__tests__/media.test.ts +0 -120
- package/adapters/feishu/__tests__/streaming-card.test.ts +0 -914
- package/adapters/telegram/__tests__/media.test.ts +0 -86
- package/adapters/telegram/__tests__/telegram.test.ts +0 -115
- package/adapters/tsconfig.json +0 -18
- package/bunfig.toml +0 -1
- package/preload.ts +0 -30
- package/scripts/count-app-loc.ts +0 -256
- package/scripts/release.ts +0 -130
- package/src/server/__tests__/conversation-service.test.ts +0 -173
- package/src/server/__tests__/conversations.test.ts +0 -458
- package/src/server/__tests__/cron-scheduler.test.ts +0 -575
- package/src/server/__tests__/e2e/business-flow.test.ts +0 -841
- package/src/server/__tests__/e2e/full-flow.test.ts +0 -357
- package/src/server/__tests__/fixtures/mock-sdk-cli.ts +0 -123
- package/src/server/__tests__/haha-oauth-api.test.ts +0 -146
- package/src/server/__tests__/haha-oauth-service.test.ts +0 -185
- package/src/server/__tests__/providers-real.test.ts +0 -244
- package/src/server/__tests__/providers.test.ts +0 -579
- package/src/server/__tests__/proxy-streaming.test.ts +0 -317
- package/src/server/__tests__/proxy-transform.test.ts +0 -469
- package/src/server/__tests__/real-llm-test.ts +0 -526
- package/src/server/__tests__/scheduled-tasks.test.ts +0 -371
- package/src/server/__tests__/sessions.test.ts +0 -786
- package/src/server/__tests__/settings.test.ts +0 -376
- package/src/server/__tests__/skills.test.ts +0 -125
- package/src/server/__tests__/tasks.test.ts +0 -171
- package/src/server/__tests__/team-watcher.test.ts +0 -400
- package/src/server/__tests__/teams.test.ts +0 -627
- package/src/server/middleware/cors.test.ts +0 -27
- package/src/utils/__tests__/cronFrequency.test.ts +0 -153
- package/src/utils/__tests__/cronTasks.test.ts +0 -204
- package/src/utils/computerUse/permissions.test.ts +0 -44
- package/stubs/ant-claude-for-chrome-mcp.ts +0 -24
- package/stubs/color-diff-napi.ts +0 -45
- package/tsconfig.json +0 -24
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'bun:test'
|
|
2
|
-
import * as fs from 'node:fs/promises'
|
|
3
|
-
import * as fsSync from 'node:fs'
|
|
4
|
-
import * as path from 'node:path'
|
|
5
|
-
import * as os from 'node:os'
|
|
6
|
-
import { AttachmentStore } from '../attachment-store.js'
|
|
7
|
-
|
|
8
|
-
let tmpRoot: string
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'att-store-test-'))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
afterEach(async () => {
|
|
15
|
-
await fs.rm(tmpRoot, { recursive: true, force: true })
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
describe('AttachmentStore', () => {
|
|
19
|
-
it('writes a buffer and returns the absolute path', async () => {
|
|
20
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
21
|
-
const target = store.resolvePath('feishu', 'sess-1', 'hello.png')
|
|
22
|
-
const written = await store.write(target, Buffer.from('PNGDATA'))
|
|
23
|
-
expect(path.isAbsolute(written)).toBe(true)
|
|
24
|
-
const content = await fs.readFile(written)
|
|
25
|
-
expect(content.toString()).toBe('PNGDATA')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('writes under {root}/{platform}/{sessionId}/', async () => {
|
|
29
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
30
|
-
const target = store.resolvePath('telegram', 'sess-42', 'foo.pdf')
|
|
31
|
-
expect(target).toContain(path.join('telegram', 'sess-42'))
|
|
32
|
-
expect(target.endsWith('foo.pdf')).toBe(true)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('sanitizes unsafe filenames (strips path separators and ..)', async () => {
|
|
36
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
37
|
-
const target = store.resolvePath('feishu', 'sess-1', '../../etc/passwd')
|
|
38
|
-
// The resulting target must still live inside the store root.
|
|
39
|
-
const root = path.resolve(tmpRoot)
|
|
40
|
-
expect(path.resolve(target).startsWith(root)).toBe(true)
|
|
41
|
-
expect(path.basename(target)).not.toContain('..')
|
|
42
|
-
expect(path.basename(target)).not.toContain('/')
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('collapses name collisions by prefixing timestamps', async () => {
|
|
46
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
47
|
-
const a = store.resolvePath('feishu', 'sess-1', 'image.png')
|
|
48
|
-
await store.write(a, Buffer.from('first'))
|
|
49
|
-
const b = store.resolvePath('feishu', 'sess-1', 'image.png')
|
|
50
|
-
expect(b).not.toBe(a)
|
|
51
|
-
await store.write(b, Buffer.from('second'))
|
|
52
|
-
const contentB = await fs.readFile(b)
|
|
53
|
-
expect(contentB.toString()).toBe('second')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('gc() removes files older than retentionMs and reports counts', async () => {
|
|
57
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 50 })
|
|
58
|
-
const target = store.resolvePath('feishu', 'sess-1', 'stale.png')
|
|
59
|
-
await store.write(target, Buffer.from('STALE'))
|
|
60
|
-
// Age the file manually
|
|
61
|
-
const past = new Date(Date.now() - 10_000)
|
|
62
|
-
await fs.utimes(target, past, past)
|
|
63
|
-
const result = await store.gc()
|
|
64
|
-
expect(result.removed).toBe(1)
|
|
65
|
-
expect(result.bytes).toBe(5)
|
|
66
|
-
await expect(fs.access(target)).rejects.toThrow()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('gc() keeps fresh files', async () => {
|
|
70
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
71
|
-
const target = store.resolvePath('feishu', 'sess-1', 'fresh.png')
|
|
72
|
-
await store.write(target, Buffer.from('FRESH'))
|
|
73
|
-
const result = await store.gc()
|
|
74
|
-
expect(result.removed).toBe(0)
|
|
75
|
-
await fs.access(target)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('resolvePath under heavy collision pressure returns unique paths', () => {
|
|
79
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 60_000 })
|
|
80
|
-
// First create a file so subsequent resolves hit the collision branch
|
|
81
|
-
const a = store.resolvePath('feishu', 'sess-1', 'race.png')
|
|
82
|
-
fsSync.writeFileSync(a, 'first')
|
|
83
|
-
// Collect 50 resolved paths in a tight loop — none should clash
|
|
84
|
-
const seen = new Set<string>()
|
|
85
|
-
for (let i = 0; i < 50; i++) {
|
|
86
|
-
seen.add(store.resolvePath('feishu', 'sess-1', 'race.png'))
|
|
87
|
-
}
|
|
88
|
-
expect(seen.size).toBe(50)
|
|
89
|
-
for (const p of seen) {
|
|
90
|
-
expect(p).not.toBe(a)
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('gc() cleans orphan .part files after a short grace period', async () => {
|
|
95
|
-
const store = new AttachmentStore({ root: tmpRoot, retentionMs: 10_000, orphanGraceMs: 50 })
|
|
96
|
-
// Simulate a crashed write — leave a .part tmp file behind
|
|
97
|
-
const dir = path.join(tmpRoot, 'feishu', 'sess-1')
|
|
98
|
-
await fs.mkdir(dir, { recursive: true })
|
|
99
|
-
const orphan = path.join(dir, 'image.png.1234.5678.part')
|
|
100
|
-
await fs.writeFile(orphan, 'ORPHAN')
|
|
101
|
-
// Age the orphan so gc considers it stale
|
|
102
|
-
const past = new Date(Date.now() - 1000)
|
|
103
|
-
await fs.utimes(orphan, past, past)
|
|
104
|
-
const result = await store.gc()
|
|
105
|
-
expect(result.removed).toBeGreaterThanOrEqual(1)
|
|
106
|
-
await expect(fs.access(orphan)).rejects.toThrow()
|
|
107
|
-
})
|
|
108
|
-
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'bun:test'
|
|
2
|
-
import { ImageBlockWatcher } from '../image-block-watcher.js'
|
|
3
|
-
|
|
4
|
-
describe('ImageBlockWatcher', () => {
|
|
5
|
-
it('extracts a markdown image with http URL', () => {
|
|
6
|
-
const w = new ImageBlockWatcher()
|
|
7
|
-
const out = w.feed('Here is  an image.')
|
|
8
|
-
expect(out.length).toBe(1)
|
|
9
|
-
const source = out[0]!.source
|
|
10
|
-
expect(source.kind).toBe('url')
|
|
11
|
-
if (source.kind === 'url') {
|
|
12
|
-
expect(source.url).toBe('https://example.com/foo.png')
|
|
13
|
-
}
|
|
14
|
-
expect(out[0]!.alt).toBe('alt')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('extracts a markdown image with absolute local path', () => {
|
|
18
|
-
const w = new ImageBlockWatcher()
|
|
19
|
-
const out = w.feed('')
|
|
20
|
-
expect(out.length).toBe(1)
|
|
21
|
-
const source = out[0]!.source
|
|
22
|
-
expect(source.kind).toBe('path')
|
|
23
|
-
if (source.kind === 'path') {
|
|
24
|
-
expect(source.path).toBe('/tmp/cat.jpg')
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('extracts a markdown image with file:// URL as path', () => {
|
|
29
|
-
const w = new ImageBlockWatcher()
|
|
30
|
-
const out = w.feed('')
|
|
31
|
-
const source = out[0]!.source
|
|
32
|
-
expect(source.kind).toBe('path')
|
|
33
|
-
if (source.kind === 'path') expect(source.path).toBe('/var/img/x.png')
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('extracts a data URI as base64', () => {
|
|
37
|
-
const w = new ImageBlockWatcher()
|
|
38
|
-
const out = w.feed('')
|
|
39
|
-
const source = out[0]!.source
|
|
40
|
-
expect(source.kind).toBe('base64')
|
|
41
|
-
if (source.kind === 'base64') {
|
|
42
|
-
expect(source.mime).toBe('image/png')
|
|
43
|
-
expect(source.data).toBe('AAAA')
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('deduplicates the same image across multiple feeds', () => {
|
|
48
|
-
const w = new ImageBlockWatcher()
|
|
49
|
-
const a = w.feed('')
|
|
50
|
-
const b = w.feed(' repeated  again')
|
|
51
|
-
expect(a.length).toBe(1)
|
|
52
|
-
expect(b.length).toBe(0)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('handles images split across feed boundaries', () => {
|
|
56
|
-
const w = new ImageBlockWatcher()
|
|
57
|
-
const a = w.feed('a  b')
|
|
59
|
-
expect(a.length).toBe(0)
|
|
60
|
-
expect(b.length).toBe(1)
|
|
61
|
-
const source = b[0]!.source
|
|
62
|
-
expect(source.kind).toBe('path')
|
|
63
|
-
if (source.kind === 'path') expect(source.path).toBe('/tmp/x.png')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('skips non-image markdown links', () => {
|
|
67
|
-
const w = new ImageBlockWatcher()
|
|
68
|
-
const out = w.feed('See [docs](https://example.com).')
|
|
69
|
-
expect(out.length).toBe(0)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('drain() returns all accumulated uploads', () => {
|
|
73
|
-
const w = new ImageBlockWatcher()
|
|
74
|
-
w.feed('')
|
|
75
|
-
w.feed(' and ')
|
|
76
|
-
const all = w.drain()
|
|
77
|
-
expect(all.length).toBe(2)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('reset() clears buffer, seen set, and accumulated list', () => {
|
|
81
|
-
const w = new ImageBlockWatcher()
|
|
82
|
-
w.feed('')
|
|
83
|
-
w.reset()
|
|
84
|
-
// After reset, drain() is empty
|
|
85
|
-
expect(w.drain().length).toBe(0)
|
|
86
|
-
// And re-feeding the same image yields a fresh emit (dedup state cleared)
|
|
87
|
-
const out = w.feed('')
|
|
88
|
-
expect(out.length).toBe(1)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('skips relative paths (cannot be resolved safely)', () => {
|
|
92
|
-
const w = new ImageBlockWatcher()
|
|
93
|
-
const out = w.feed(' and ')
|
|
94
|
-
expect(out.length).toBe(1)
|
|
95
|
-
const source = out[0]!.source
|
|
96
|
-
expect(source.kind).toBe('path')
|
|
97
|
-
if (source.kind === 'path') expect(source.path).toBe('/tmp/ok.png')
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('extracts multiple images from a single feed chunk in order', () => {
|
|
101
|
-
const w = new ImageBlockWatcher()
|
|
102
|
-
const out = w.feed('  ')
|
|
103
|
-
expect(out.length).toBe(3)
|
|
104
|
-
expect(out[0]!.source.kind).toBe('path')
|
|
105
|
-
expect(out[1]!.source.kind).toBe('url')
|
|
106
|
-
expect(out[2]!.source.kind).toBe('base64')
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('rejects malformed data URI (not base64)', () => {
|
|
110
|
-
const w = new ImageBlockWatcher()
|
|
111
|
-
const out = w.feed('')
|
|
112
|
-
// Not in `;base64,` form → classify returns null → skipped
|
|
113
|
-
expect(out.length).toBe(0)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* card-errors 单元测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'bun:test'
|
|
6
|
-
import {
|
|
7
|
-
CARD_ERROR,
|
|
8
|
-
CARD_CONTENT_SUB_ERROR,
|
|
9
|
-
extractLarkApiCode,
|
|
10
|
-
extractSubCode,
|
|
11
|
-
parseCardApiError,
|
|
12
|
-
isCardRateLimitError,
|
|
13
|
-
isCardTableLimitError,
|
|
14
|
-
} from '../card-errors.js'
|
|
15
|
-
|
|
16
|
-
describe('extractLarkApiCode', () => {
|
|
17
|
-
it('从 err.code 直接提取', () => {
|
|
18
|
-
expect(extractLarkApiCode({ code: 230020 })).toBe(230020)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('从 err.data.code 提取', () => {
|
|
22
|
-
expect(extractLarkApiCode({ data: { code: 230099 } })).toBe(230099)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('从 err.response.data.code 提取(Axios 风格)', () => {
|
|
26
|
-
expect(extractLarkApiCode({ response: { data: { code: 99991672 } } })).toBe(99991672)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('数字字符串被强制转成 number', () => {
|
|
30
|
-
expect(extractLarkApiCode({ code: '230020' })).toBe(230020)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('三层结构优先级: err.code > err.data.code > err.response.data.code', () => {
|
|
34
|
-
const err = {
|
|
35
|
-
code: 1,
|
|
36
|
-
data: { code: 2 },
|
|
37
|
-
response: { data: { code: 3 } },
|
|
38
|
-
}
|
|
39
|
-
expect(extractLarkApiCode(err)).toBe(1)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('none → undefined', () => {
|
|
43
|
-
expect(extractLarkApiCode({})).toBeUndefined()
|
|
44
|
-
expect(extractLarkApiCode(null)).toBeUndefined()
|
|
45
|
-
expect(extractLarkApiCode(undefined)).toBeUndefined()
|
|
46
|
-
expect(extractLarkApiCode('just a string')).toBeUndefined()
|
|
47
|
-
expect(extractLarkApiCode(new Error('plain'))).toBeUndefined()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('非有限数字被忽略', () => {
|
|
51
|
-
expect(extractLarkApiCode({ code: NaN })).toBeUndefined()
|
|
52
|
-
expect(extractLarkApiCode({ code: 'not-a-number' })).toBeUndefined()
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('extractSubCode', () => {
|
|
57
|
-
it('识别标准的 ErrCode: 11310', () => {
|
|
58
|
-
const msg = 'Failed to create card content, ext=ErrCode: 11310; ErrMsg: card table number over limit'
|
|
59
|
-
expect(extractSubCode(msg)).toBe(11310)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('无 ErrCode 时返回 null', () => {
|
|
63
|
-
expect(extractSubCode('random error message')).toBeNull()
|
|
64
|
-
expect(extractSubCode('')).toBeNull()
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('ErrCode 大小写容错(冒号后多空格)', () => {
|
|
68
|
-
expect(extractSubCode('ErrCode: 42')).toBe(42)
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
describe('parseCardApiError', () => {
|
|
73
|
-
it('从 SDK 风格错误提取完整结构', () => {
|
|
74
|
-
const err = { code: 230099, msg: 'ErrCode: 11310; ErrMsg: card table number over limit' }
|
|
75
|
-
const parsed = parseCardApiError(err)
|
|
76
|
-
expect(parsed).toEqual({
|
|
77
|
-
code: 230099,
|
|
78
|
-
subCode: 11310,
|
|
79
|
-
errMsg: 'ErrCode: 11310; ErrMsg: card table number over limit',
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('从 Axios 风格错误(response.data.msg)提取', () => {
|
|
84
|
-
const err = {
|
|
85
|
-
response: {
|
|
86
|
-
data: {
|
|
87
|
-
code: 230020,
|
|
88
|
-
msg: 'rate limited',
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
const parsed = parseCardApiError(err)
|
|
93
|
-
expect(parsed?.code).toBe(230020)
|
|
94
|
-
expect(parsed?.errMsg).toBe('rate limited')
|
|
95
|
-
expect(parsed?.subCode).toBeNull()
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('无 code 时返回 null', () => {
|
|
99
|
-
expect(parseCardApiError({})).toBeNull()
|
|
100
|
-
expect(parseCardApiError(null)).toBeNull()
|
|
101
|
-
expect(parseCardApiError('string')).toBeNull()
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('有 code 无 msg 时 errMsg 为空字符串', () => {
|
|
105
|
-
const parsed = parseCardApiError({ code: 230020 })
|
|
106
|
-
expect(parsed).toEqual({ code: 230020, subCode: null, errMsg: '' })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('fallback 到 err.message', () => {
|
|
110
|
-
const err = Object.assign(new Error('fallback text'), { code: 230099 })
|
|
111
|
-
const parsed = parseCardApiError(err)
|
|
112
|
-
expect(parsed?.errMsg).toBe('fallback text')
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
describe('isCardRateLimitError', () => {
|
|
117
|
-
it('识别 230020', () => {
|
|
118
|
-
expect(isCardRateLimitError({ code: 230020 })).toBe(true)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('识别 Axios 风格 230020', () => {
|
|
122
|
-
expect(isCardRateLimitError({ response: { data: { code: 230020 } } })).toBe(true)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it('不匹配其他 code', () => {
|
|
126
|
-
expect(isCardRateLimitError({ code: 230099 })).toBe(false)
|
|
127
|
-
expect(isCardRateLimitError({ code: 99991672 })).toBe(false)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('非错误对象返回 false', () => {
|
|
131
|
-
expect(isCardRateLimitError(null)).toBe(false)
|
|
132
|
-
expect(isCardRateLimitError({})).toBe(false)
|
|
133
|
-
expect(isCardRateLimitError(new Error('random'))).toBe(false)
|
|
134
|
-
})
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
describe('isCardTableLimitError', () => {
|
|
138
|
-
const validMsg = 'Failed to create card content, ext=ErrCode: 11310; ErrMsg: card table number over limit; ErrorValue: table; '
|
|
139
|
-
|
|
140
|
-
it('严格三条件匹配: code=230099 + subCode=11310 + msg 含 table number over limit', () => {
|
|
141
|
-
const err = { code: CARD_ERROR.CARD_CONTENT_FAILED, msg: validMsg }
|
|
142
|
-
expect(isCardTableLimitError(err)).toBe(true)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('从 Axios 风格的 response.data 匹配', () => {
|
|
146
|
-
const err = {
|
|
147
|
-
response: {
|
|
148
|
-
data: {
|
|
149
|
-
code: 230099,
|
|
150
|
-
msg: validMsg,
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
}
|
|
154
|
-
expect(isCardTableLimitError(err)).toBe(true)
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('230099 + 11310 但没有 "table number over limit" 字样 → false(其它元素超限)', () => {
|
|
158
|
-
const err = {
|
|
159
|
-
code: CARD_ERROR.CARD_CONTENT_FAILED,
|
|
160
|
-
msg: 'ErrCode: 11310; ErrMsg: some other element limit; ',
|
|
161
|
-
}
|
|
162
|
-
expect(isCardTableLimitError(err)).toBe(false)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('code 不是 230099 → false', () => {
|
|
166
|
-
const err = { code: 230020, msg: validMsg }
|
|
167
|
-
expect(isCardTableLimitError(err)).toBe(false)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('没有 subCode → false', () => {
|
|
171
|
-
const err = { code: 230099, msg: 'card table number over limit (no ErrCode)' }
|
|
172
|
-
expect(isCardTableLimitError(err)).toBe(false)
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it('不区分 "table number" 的大小写', () => {
|
|
176
|
-
const err = {
|
|
177
|
-
code: 230099,
|
|
178
|
-
msg: 'ErrCode: 11310; ErrMsg: CARD TABLE NUMBER OVER LIMIT; ',
|
|
179
|
-
}
|
|
180
|
-
expect(isCardTableLimitError(err)).toBe(true)
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
describe('常量值', () => {
|
|
185
|
-
it('CARD_ERROR.RATE_LIMITED === 230020', () => {
|
|
186
|
-
expect(CARD_ERROR.RATE_LIMITED).toBe(230020)
|
|
187
|
-
})
|
|
188
|
-
it('CARD_ERROR.CARD_CONTENT_FAILED === 230099', () => {
|
|
189
|
-
expect(CARD_ERROR.CARD_CONTENT_FAILED).toBe(230099)
|
|
190
|
-
})
|
|
191
|
-
it('CARD_CONTENT_SUB_ERROR.ELEMENT_LIMIT === 11310', () => {
|
|
192
|
-
expect(CARD_CONTENT_SUB_ERROR.ELEMENT_LIMIT).toBe(11310)
|
|
193
|
-
})
|
|
194
|
-
})
|