-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcockroachdbError.spec.ts
More file actions
53 lines (45 loc) · 1.47 KB
/
cockroachdbError.spec.ts
File metadata and controls
53 lines (45 loc) · 1.47 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
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/client'
import { describe, expect, it } from 'vitest'
import { isCockroachDBRetryTransaction } from './cockroachdbError.ts'
import { PRISMA_SERIALIZATION_ERROR } from './prismaError.ts'
describe('cockroachdbError', () => {
it('should return false without meta', () => {
// Given
const error = new PrismaClientKnownRequestError('test', {
code: PRISMA_SERIALIZATION_ERROR,
clientVersion: '1',
})
// When - Then
expect(isCockroachDBRetryTransaction(error)).toBe(false)
})
it('should return false for a wrong meta field', () => {
// Given
const error = new PrismaClientKnownRequestError('test', {
code: 'P100',
clientVersion: '1',
meta: { wrong: 'meta' },
})
// When - Then
expect(isCockroachDBRetryTransaction(error)).toBe(false)
})
it('should return false for wrong meta.code', () => {
// Given
const error = new PrismaClientKnownRequestError('test', {
code: 'P100',
clientVersion: '1',
meta: { code: '40002' },
})
// When - Then
expect(isCockroachDBRetryTransaction(error)).toBe(false)
})
it('should return try for a CRDB retry transaction error', () => {
// Given
const error = new PrismaClientKnownRequestError('test', {
code: 'P100',
clientVersion: '1',
meta: { code: '40001' },
})
// When - Then
expect(isCockroachDBRetryTransaction(error)).toBe(true)
})
})