summaryrefslogtreecommitdiff
path: root/website/.vitepress/theme/components/useCompatibilityData.test.ts
blob: ec99cffb832545934a3be0bc0a57ed4bb98b2d99 (plain)
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
85
86
import { describe, expect, test } from 'bun:test';
import {
  checkCompatibility,
  isCompatible,
  olderSide,
  type ProtocolVersion,
} from './useCompatibilityData';

function protocol(
  major: number,
  minor: number,
  patch: number,
  minSupportedMinor = 0,
): ProtocolVersion {
  return { major, minor, patch, minSupportedMinor };
}

describe('checkCompatibility', () => {
  test('calls an identical protocol on both ends fully compatible', () => {
    expect(checkCompatibility(protocol(1, 0, 1), protocol(1, 0, 1))).toBe(
      'compatible',
    );
  });

  test('reports a degraded pair when Paper sends a sub-channel Velocity ignores', () => {
    // Paper 1.3.0 speaks 1.0.1 — the PATCH that added cross-server direct
    // messages — while Velocity 1.1.0 stopped at 1.0.0.
    expect(checkCompatibility(protocol(1, 0, 1), protocol(1, 0, 0))).toBe(
      'degraded',
    );
  });

  test('reports a degraded pair when Velocity offers a sub-channel Paper never sends', () => {
    expect(checkCompatibility(protocol(1, 0, 0), protocol(1, 0, 1))).toBe(
      'degraded',
    );
  });

  test('reports a degraded pair when Paper trails by a MINOR still inside the window', () => {
    expect(checkCompatibility(protocol(1, 0, 0), protocol(1, 1, 0))).toBe(
      'degraded',
    );
  });

  test('rejects a MAJOR mismatch', () => {
    expect(checkCompatibility(protocol(1, 0, 0), protocol(2, 0, 0))).toBe(
      'major-mismatch',
    );
  });

  test('rejects Paper running ahead of Velocity by a MINOR', () => {
    expect(checkCompatibility(protocol(1, 1, 0), protocol(1, 0, 0))).toBe(
      'paper-too-new',
    );
  });

  test('rejects Paper older than the deprecation window admits', () => {
    expect(checkCompatibility(protocol(1, 0, 0), protocol(1, 2, 0, 1))).toBe(
      'paper-too-old',
    );
  });
});

describe('isCompatible', () => {
  test('holds for a degraded pair, which still completes the handshake', () => {
    expect(isCompatible(protocol(1, 0, 1), protocol(1, 0, 0))).toBe(true);
  });

  test('fails for a pair the handshake rejects', () => {
    expect(isCompatible(protocol(1, 1, 0), protocol(1, 0, 0))).toBe(false);
  });
});

describe('olderSide', () => {
  test('names Velocity when it trails by a PATCH', () => {
    expect(olderSide(protocol(1, 0, 1), protocol(1, 0, 0))).toBe('velocity');
  });

  test('names Paper when it trails by a PATCH', () => {
    expect(olderSide(protocol(1, 0, 0), protocol(1, 0, 1))).toBe('paper');
  });

  test('lets a MINOR gap outrank the PATCH comparison', () => {
    expect(olderSide(protocol(1, 0, 9), protocol(1, 1, 0))).toBe('paper');
  });
});