Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

change-diff.test.ts

53 lines1.6 KB

1import { describe, expect, it } from 'vitest'
2​
3import { changeDiffs } from './change-diff.ts'
4​
5describe('changeDiffs', () => {
6 it('shows each changed path with its before and after value', () => {
7 const payload = {
8 before: {
9 contextWindow: 262144,
10 deprecated: true,
11 capabilities: { structured_outputs: false },
12 pricing: { tables: { rate: { base: { input_tokens: 2.6e-7 } } } },
13 },
14 after: {
15 contextWindow: null,
16 deprecated: false,
17 capabilities: { structured_outputs: true, response_format: true },
18 pricing: { tables: { rate: { base: { input_tokens: 4.7e-7 } } } },
19 },
20 changed: [
21 'capabilities.response_format',
22 'contextWindow',
23 'deprecated',
24 'pricing.tables.rate.base.input_tokens',
25 ],
26 }
27 expect(changeDiffs(payload)).toEqual([
28 { path: 'capabilities.response_format', before: '—', after: 'true' },
29 { path: 'contextWindow', before: '262144', after: 'null' },
30 { path: 'deprecated', before: 'true', after: 'false' },
31 {
32 path: 'pricing.tables.rate.base.input_tokens',
33 before: '$0.26/M',
34 after: '$0.47/M',
35 },
36 ])
37 })
38​
39 it('names a price that appeared or went away', () => {
40 expect(
41 changeDiffs({
42 before: { pricing: null },
43 after: { pricing: { tables: {} } },
44 changed: ['pricing'],
45 }),
46 ).toEqual([{ path: 'pricing', before: 'null', after: 'card' }])
47 })
48​
49 it('shows nothing for a payload with no changed list', () => {
50 expect(changeDiffs({ before: {}, after: {} })).toEqual([])
51 expect(changeDiffs(null)).toEqual([])
52 })
53})