Skip to content

Commit 0fc3d48

Browse files
committed
test(drizzle): add encryption/decryption verification tests to JSONB test suite
Add comprehensive validation tests across all 5 JSONB test files to verify: - Data stored in database is encrypted (not plaintext) - Encrypted structure contains expected ciphertext markers - Data can be decrypted and matches original values - Round-trip encryption/decryption preserves all fields Each file now includes: - Encryption Verification describe block - Decryption Verification describe block - Query Execution tests (jsonb-comparison.test.ts) Also adds shared test data fixtures in jsonb-test-data.ts.
1 parent ccea674 commit 0fc3d48

File tree

6 files changed

+3677
-0
lines changed

6 files changed

+3677
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* JSONB Test Data Fixtures
3+
*
4+
* Shared test data matching the proxy test patterns for JSONB operations.
5+
* These fixtures ensure consistency between Drizzle integration tests and
6+
* the proxy reference tests.
7+
*/
8+
9+
/**
10+
* Standard JSONB test data structure
11+
* Matches the proxy test data: {"string": "hello", "number": 42, ...}
12+
*/
13+
export const standardJsonbData = {
14+
string: 'hello',
15+
number: 42,
16+
array_string: ['hello', 'world'],
17+
array_number: [42, 84],
18+
nested: {
19+
number: 1815,
20+
string: 'world',
21+
},
22+
}
23+
24+
/**
25+
* Type definition for standard JSONB data
26+
*/
27+
export type StandardJsonbData = typeof standardJsonbData
28+
29+
/**
30+
* Comparison test data (5 rows)
31+
* Used for testing WHERE clause comparisons with equality and range operations
32+
* Pattern: string A-E, number 1-5
33+
*/
34+
export const comparisonTestData = [
35+
{ string: 'A', number: 1 },
36+
{ string: 'B', number: 2 },
37+
{ string: 'C', number: 3 },
38+
{ string: 'D', number: 4 },
39+
{ string: 'E', number: 5 },
40+
]
41+
42+
/**
43+
* Type definition for comparison test data
44+
*/
45+
export type ComparisonTestData = (typeof comparisonTestData)[number]
46+
47+
/**
48+
* Large dataset generator for containment index tests
49+
* Creates N rows following the proxy pattern:
50+
* { id: 1000000 + n, string: "value_" + (n % 10), number: n % 10 }
51+
*
52+
* @param count - Number of records to generate (default 500)
53+
* @returns Array of test records
54+
*/
55+
export function generateLargeDataset(count = 500): Array<{
56+
id: number
57+
string: string
58+
number: number
59+
}> {
60+
return Array.from({ length: count }, (_, n) => ({
61+
id: 1000000 + n,
62+
string: `value_${n % 10}`,
63+
number: n % 10,
64+
}))
65+
}
66+
67+
/**
68+
* Extended JSONB data with additional fields for comprehensive testing
69+
* Includes all standard fields plus edge cases
70+
*/
71+
export const extendedJsonbData = {
72+
...standardJsonbData,
73+
// Additional fields for edge case testing
74+
boolean_field: true,
75+
null_field: null,
76+
float_field: 99.99,
77+
negative_number: -500,
78+
empty_array: [],
79+
empty_object: {},
80+
deep_nested: {
81+
level1: {
82+
level2: {
83+
level3: {
84+
value: 'deep',
85+
},
86+
},
87+
},
88+
},
89+
unicode_string: '你好世界 🌍',
90+
special_chars: 'Hello "world" with \'quotes\'',
91+
}
92+
93+
/**
94+
* Type definition for extended JSONB data
95+
*/
96+
export type ExtendedJsonbData = typeof extendedJsonbData
97+
98+
/**
99+
* JSONB data variations for containment tests
100+
* Each object represents a different containment pattern
101+
*/
102+
export const containmentVariations = {
103+
// String field containment
104+
stringOnly: { string: 'hello' },
105+
// Number field containment
106+
numberOnly: { number: 42 },
107+
// Array containment
108+
stringArray: { array_string: ['hello', 'world'] },
109+
numberArray: { array_number: [42, 84] },
110+
// Nested object containment
111+
nestedFull: { nested: { number: 1815, string: 'world' } },
112+
nestedPartial: { nested: { string: 'world' } },
113+
// Multiple field containment
114+
multipleFields: { string: 'hello', number: 42 },
115+
}
116+
117+
/**
118+
* Path test cases for field access and path operations
119+
* Maps path expressions to expected values from standardJsonbData
120+
*/
121+
export const pathTestCases = {
122+
// Simple paths
123+
string: 'hello',
124+
number: 42,
125+
// Array paths
126+
array_string: ['hello', 'world'],
127+
array_number: [42, 84],
128+
// Nested paths
129+
nested: { number: 1815, string: 'world' },
130+
'nested.string': 'world',
131+
'nested.number': 1815,
132+
// Unknown paths (should return null/empty)
133+
unknown_field: null,
134+
'nested.unknown': null,
135+
}
136+
137+
/**
138+
* Array wildcard test cases
139+
* Tests $.array[*] and $.array[@] patterns
140+
*/
141+
export const arrayWildcardTestCases = {
142+
'array_string[*]': ['hello', 'world'],
143+
'array_string[@]': ['hello', 'world'],
144+
'array_number[*]': [42, 84],
145+
'array_number[@]': [42, 84],
146+
}
147+
148+
/**
149+
* Helper to create a unique test run ID for isolating test data
150+
*/
151+
export function createTestRunId(prefix = 'jsonb-test'): string {
152+
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
153+
}

0 commit comments

Comments
 (0)