summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/decorators/cd-encode.spec.ts
blob: 49b504fd6a9cbdb4fba7aa6a2e89575878e21e29 (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
import { cdEncode, cdEncodeNot } from './cd-encode';

describe('cdEncode', () => {
  @cdEncode
  class ClassA {
    x2: string;
    y2: string;

    methodA(x1: string, @cdEncodeNot y1: string) {
      this.x2 = x1;
      this.y2 = y1;
    }
  }

  class ClassB {
    x2: string;
    y2: string;

    @cdEncode
    methodB(x1: string, @cdEncodeNot y1: string) {
      this.x2 = x1;
      this.y2 = y1;
    }
  }

  const word = 'a+b/c-d';

  it('should encode all params of ClassA, with exception of y1', () => {
    const a = new ClassA();
    a.methodA(word, word);
    expect(a.x2).toBe('a%2Bb%2Fc-d');
    expect(a.y2).toBe(word);
  });

  it('should encode all params of methodB, with exception of y1', () => {
    const b = new ClassB();
    b.methodB(word, word);
    expect(b.x2).toBe('a%2Bb%2Fc-d');
    expect(b.y2).toBe(word);
  });
});