-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompatibility.test.ts
More file actions
84 lines (66 loc) · 3.17 KB
/
Copy pathcompatibility.test.ts
File metadata and controls
84 lines (66 loc) · 3.17 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { checkCompatibility, SDK_VERSION, parseVersion } from './compatibility';
// Helper to mock invoke function
let mockInvoke: ReturnType<typeof vi.fn<(method: string) => Promise<any>>>;
beforeEach(() => {
mockInvoke = vi.fn();
});
describe('Version Parsing', () => {
it('parses clean version strings', () => {
expect(parseVersion('1.2.3')).toMatchObject({ major: 1, minor: 2, patch: 3 });
});
it("handles leading 'v' prefix case-insensitively", () => {
expect(parseVersion('v1.2.3')).toMatchObject({ major: 1, minor: 2, patch: 3 });
expect(parseVersion('V2.4.6')).toMatchObject({ major: 2, minor: 4, patch: 6 });
});
it('ignores pre-release or build suffixes', () => {
expect(parseVersion('1.0.0-beta.1')).toMatchObject({ major: 1, minor: 0, patch: 0 });
expect(parseVersion('0.1.0-alpha+build.123')).toMatchObject({ major: 0, minor: 1, patch: 0 });
});
it('handles incomplete version strings gracefully', () => {
expect(parseVersion('1')).toMatchObject({ major: 1, minor: 0, patch: 0 });
expect(parseVersion('1.2')).toMatchObject({ major: 1, minor: 2, patch: 0 });
expect(parseVersion('')).toMatchObject({ major: 0, minor: 0, patch: 0 });
});
});
describe('checkCompatibility (standalone)', () => {
it('passes when contract matches SDK exactly', async () => {
mockInvoke.mockResolvedValue('0.1.0');
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(true);
expect(result.contractVersion).toBe('0.1.0');
expect(result.sdkVersion).toBe(SDK_VERSION);
expect(result.issues).toHaveLength(0);
});
it('passes when contract is newer minor/patch version', async () => {
mockInvoke.mockResolvedValue('0.1.5');
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(true);
expect(result.issues).toHaveLength(0);
});
it('fails when contract version is older than minimum required', async () => {
mockInvoke.mockResolvedValue('0.0.9');
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(false);
expect(result.issues[0]).toContain('older than the minimum required version');
});
it('fails when contract version is a higher major version (potentially breaking)', async () => {
mockInvoke.mockResolvedValue('1.0.0');
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(false);
expect(result.issues[0]).toContain('higher major version');
});
it('handles contract returning an object with a version property', async () => {
mockInvoke.mockResolvedValue({ version: '0.1.2' });
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(true);
expect(result.contractVersion).toBe('0.1.2');
});
it('handles contract invocation failures cleanly', async () => {
mockInvoke.mockRejectedValue(new Error('RPC Connection failed'));
const result = await checkCompatibility(mockInvoke);
expect(result.compatible).toBe(false);
expect(result.contractVersion).toBe('unknown');
expect(result.issues[0]).toContain('Failed to retrieve contract version');
});
});