|
1 | 1 | import { parserUtils } from '../src/parser/parser_utils.js';
|
2 | 2 |
|
3 | 3 | describe('ParserUtils', function () {
|
4 |
| - describe('splitVAST', function () { |
5 |
| - it('should parse normally defined vast pods', () => { |
6 |
| - const input = [ |
7 |
| - { id: 2, sequence: 1 }, |
8 |
| - { id: 3, sequence: 2 }, |
9 |
| - { id: 4 }, |
10 |
| - { id: 5, sequence: 1 }, |
11 |
| - { id: 6, sequence: 2 }, |
12 |
| - { id: 7, sequence: 3 }, |
13 |
| - { id: 8, sequence: 1 }, |
14 |
| - { id: 9, sequence: 2 }, |
15 |
| - { id: 10 }, |
16 |
| - { id: 11, sequence: 1 }, |
17 |
| - { id: 12 }, |
| 4 | + describe('getSortedAdPods', function () { |
| 5 | + it('should return sorted ad pods based on sequence attribute', function () { |
| 6 | + const ads = [ |
| 7 | + { sequence: '3', id: 'ad3' }, |
| 8 | + { sequence: '1', id: 'ad1' }, |
| 9 | + { sequence: '2', id: 'ad2' }, |
18 | 10 | ];
|
19 |
| - |
20 |
| - const expectedOutput = [ |
21 |
| - [ |
22 |
| - { id: 2, sequence: 1 }, |
23 |
| - { id: 3, sequence: 2 }, |
24 |
| - ], |
25 |
| - [{ id: 4 }], |
26 |
| - [ |
27 |
| - { id: 5, sequence: 1 }, |
28 |
| - { id: 6, sequence: 2 }, |
29 |
| - { id: 7, sequence: 3 }, |
30 |
| - ], |
31 |
| - [ |
32 |
| - { id: 8, sequence: 1 }, |
33 |
| - { id: 9, sequence: 2 }, |
34 |
| - ], |
35 |
| - [{ id: 10 }], |
36 |
| - [{ id: 11, sequence: 1 }], |
37 |
| - [{ id: 12 }], |
38 |
| - ]; |
39 |
| - |
40 |
| - const output = parserUtils.splitVAST(input); |
41 |
| - |
42 |
| - expect(output).toEqual(expectedOutput); |
| 11 | + const sortedAds = parserUtils.getSortedAdPods(ads); |
| 12 | + expect(sortedAds).toEqual([ |
| 13 | + { sequence: '1', id: 'ad1' }, |
| 14 | + { sequence: '2', id: 'ad2' }, |
| 15 | + { sequence: '3', id: 'ad3' }, |
| 16 | + ]); |
43 | 17 | });
|
44 | 18 |
|
45 |
| - it('should parse vast pods with single sequence', () => { |
46 |
| - const input = [ |
47 |
| - { id: 1, sequence: 1 }, |
48 |
| - { id: 2, sequence: 1 }, |
49 |
| - { id: 3, sequence: 1 }, |
50 |
| - ]; |
51 |
| - |
52 |
| - const expectedOutput = [ |
53 |
| - [{ id: 1, sequence: 1 }], |
54 |
| - [{ id: 2, sequence: 1 }], |
55 |
| - [{ id: 3, sequence: 1 }], |
| 19 | + it('should filter out ads without sequence attribute', function () { |
| 20 | + const ads = [ |
| 21 | + { sequence: '3', id: 'ad3' }, |
| 22 | + { id: 'adWithoutSequence' }, |
| 23 | + { sequence: '2', id: 'ad2' }, |
| 24 | + { sequence: '1', id: 'ad1' }, |
56 | 25 | ];
|
57 |
| - |
58 |
| - const output = parserUtils.splitVAST(input); |
59 |
| - |
60 |
| - expect(output).toEqual(expectedOutput); |
61 |
| - }); |
62 |
| - |
63 |
| - it('should parse vast pods with no pods', () => { |
64 |
| - const input = [{ id: 1 }, { id: 2 }, { id: 3 }]; |
65 |
| - |
66 |
| - const expectedOutput = [[{ id: 1 }], [{ id: 2 }], [{ id: 3 }]]; |
67 |
| - |
68 |
| - const output = parserUtils.splitVAST(input); |
69 |
| - |
70 |
| - expect(output).toEqual(expectedOutput); |
| 26 | + const sortedAds = parserUtils.getSortedAdPods(ads); |
| 27 | + expect(sortedAds).toEqual([ |
| 28 | + { sequence: '1', id: 'ad1' }, |
| 29 | + { sequence: '2', id: 'ad2' }, |
| 30 | + { sequence: '3', id: 'ad3' }, |
| 31 | + ]); |
71 | 32 | });
|
72 | 33 |
|
73 |
| - it('should parse vast pods with weird sequences', () => { |
74 |
| - const input = [ |
75 |
| - { id: 1, sequence: 99 }, |
76 |
| - { id: 2, sequence: 99 }, |
77 |
| - { id: 3, sequence: 99 }, |
| 34 | + it('should return an empty array if no adPods are provided', function () { |
| 35 | + const ads = [ |
| 36 | + { id: 'adWithoutSequence1' }, |
| 37 | + { id: 'adWithoutSequence2' }, |
| 38 | + { id: 'adWithoutSequence3' }, |
78 | 39 | ];
|
79 |
| - |
80 |
| - const expectedOutput = [[{ id: 1 }], [{ id: 2 }], [{ id: 3 }]]; |
81 |
| - |
82 |
| - const output = parserUtils.splitVAST(input); |
83 |
| - |
84 |
| - expect(output).toEqual(expectedOutput); |
| 40 | + const sortedAds = parserUtils.getSortedAdPods(ads); |
| 41 | + expect(sortedAds).toEqual([]); |
85 | 42 | });
|
| 43 | + }); |
86 | 44 |
|
87 |
| - it('should parse vast pods with sequences that not start with index = 1', () => { |
88 |
| - const input = [ |
89 |
| - { id: 1, sequence: 2 }, |
90 |
| - { id: 4 }, |
91 |
| - { id: 98, sequence: 3 }, |
92 |
| - { id: 99, sequence: 4 }, |
93 |
| - { id: 5, sequence: 1 }, |
94 |
| - { id: 6, sequence: 2 }, |
95 |
| - { id: 7, sequence: 3 }, |
96 |
| - { id: 8, sequence: 1 }, |
97 |
| - { id: 9, sequence: 2 }, |
98 |
| - { id: 10 }, |
99 |
| - { id: 11, sequence: 1 }, |
100 |
| - { id: 12 }, |
101 |
| - ]; |
102 |
| - |
103 |
| - const expectedOutput = [ |
104 |
| - [{ id: 1 }], |
105 |
| - [{ id: 4 }], |
106 |
| - [{ id: 98 }], |
107 |
| - [{ id: 99 }], |
108 |
| - [ |
109 |
| - { id: 5, sequence: 1 }, |
110 |
| - { id: 6, sequence: 2 }, |
111 |
| - { id: 7, sequence: 3 }, |
112 |
| - ], |
113 |
| - [ |
114 |
| - { id: 8, sequence: 1 }, |
115 |
| - { id: 9, sequence: 2 }, |
116 |
| - ], |
117 |
| - [{ id: 10 }], |
118 |
| - [{ id: 11, sequence: 1 }], |
119 |
| - [{ id: 12 }], |
| 45 | + describe('getStandAloneAds', function () { |
| 46 | + it('should return standalone ads without sequence attribute', function () { |
| 47 | + const ads = [ |
| 48 | + { sequence: '3', id: 'ad3' }, |
| 49 | + { id: 'adWithoutSequence1' }, |
| 50 | + { sequence: '1', id: 'ad1' }, |
| 51 | + { id: 'adWithoutSequence2' }, |
120 | 52 | ];
|
121 |
| - |
122 |
| - const output = parserUtils.splitVAST(input); |
123 |
| - |
124 |
| - expect(output).toEqual(expectedOutput); |
| 53 | + const standAloneAds = parserUtils.getStandAloneAds(ads); |
| 54 | + expect(standAloneAds).toEqual([ |
| 55 | + { id: 'adWithoutSequence1' }, |
| 56 | + { id: 'adWithoutSequence2' }, |
| 57 | + ]); |
125 | 58 | });
|
126 | 59 |
|
127 |
| - it('should parse vast pods with sequences that not start with index = 1, and not following incrementally', () => { |
128 |
| - const input = [ |
129 |
| - { id: 1, sequence: 2 }, |
130 |
| - { id: 2, sequence: 4 }, |
131 |
| - { id: 4 }, |
132 |
| - { id: 98, sequence: 3 }, |
133 |
| - { id: 99, sequence: 4 }, |
134 |
| - { id: 100, sequence: 17 }, |
135 |
| - { id: 101, sequence: 18 }, |
136 |
| - { id: 5, sequence: 1 }, |
137 |
| - { id: 6, sequence: 2 }, |
138 |
| - { id: 7, sequence: 3 }, |
139 |
| - { id: 8, sequence: 1 }, |
140 |
| - { id: 9, sequence: 2 }, |
141 |
| - { id: 10 }, |
142 |
| - { id: 11, sequence: 1 }, |
143 |
| - { id: 12 }, |
| 60 | + it('should return an empty array if all ads have sequence attribute', function () { |
| 61 | + const ads = [ |
| 62 | + { sequence: '1', id: 'ad1' }, |
| 63 | + { sequence: '2', id: 'ad2' }, |
144 | 64 | ];
|
145 |
| - |
146 |
| - const expectedOutput = [ |
147 |
| - [{ id: 1 }], |
148 |
| - [{ id: 2 }], |
149 |
| - [{ id: 4 }], |
150 |
| - [{ id: 98 }], |
151 |
| - [{ id: 99 }], |
152 |
| - [{ id: 100 }], |
153 |
| - [{ id: 101 }], |
154 |
| - [ |
155 |
| - { id: 5, sequence: 1 }, |
156 |
| - { id: 6, sequence: 2 }, |
157 |
| - { id: 7, sequence: 3 }, |
158 |
| - ], |
159 |
| - [ |
160 |
| - { id: 8, sequence: 1 }, |
161 |
| - { id: 9, sequence: 2 }, |
162 |
| - ], |
163 |
| - [{ id: 10 }], |
164 |
| - [{ id: 11, sequence: 1 }], |
165 |
| - [{ id: 12 }], |
166 |
| - ]; |
167 |
| - |
168 |
| - const output = parserUtils.splitVAST(input); |
169 |
| - |
170 |
| - expect(output).toEqual(expectedOutput); |
| 65 | + const standAloneAds = parserUtils.getStandAloneAds(ads); |
| 66 | + expect(standAloneAds).toEqual([]); |
171 | 67 | });
|
172 | 68 | });
|
173 | 69 |
|
|
0 commit comments