|
4 | 4 | processFingerpostAAPCategoryCodes, |
5 | 5 | processFingerpostAFPCategoryCodes, |
6 | 6 | processFingerpostAPCategoryCodes, |
7 | | - processFingerpostPAAPICategoryCodes, |
8 | 7 | processFingerpostPACategoryCodes, |
9 | 8 | processReutersDestinationCodes, |
10 | 9 | processUnknownFingerpostCategoryCodes, |
@@ -193,77 +192,92 @@ describe('processFingerpostAFPCategoryCodes', () => { |
193 | 192 |
|
194 | 193 | describe('processFingerpostPACategoryCodes', () => { |
195 | 194 | describe('processFingerpostPACategoryCodes', () => { |
196 | | - it('should return an empty array if provided with an empty array', () => { |
197 | | - expect(processFingerpostPACategoryCodes([])).toEqual([]); |
198 | | - }); |
199 | | - |
200 | | - it('should strip out service codes', () => { |
201 | | - expect(processFingerpostPACategoryCodes(['service:news'])).toEqual([]); |
202 | | - }); |
203 | | - |
204 | | - it('should strip out empty iptccat entries', () => { |
205 | | - expect( |
206 | | - processFingerpostPACategoryCodes(['iptccat:', 'iptccat:a']), |
207 | | - ).toEqual(['paCat:a']); |
| 195 | + describe('when mediaCatCodes is not provided', () => { |
| 196 | + it('should return an empty array if provided with an empty array', () => { |
| 197 | + expect(processFingerpostPACategoryCodes([])).toEqual([]); |
| 198 | + }); |
| 199 | + |
| 200 | + it('should strip out service codes', () => { |
| 201 | + expect(processFingerpostPACategoryCodes(['service:news'])).toEqual([]); |
| 202 | + }); |
| 203 | + |
| 204 | + it('should strip out empty iptccat entries', () => { |
| 205 | + expect( |
| 206 | + processFingerpostPACategoryCodes(['iptccat:', 'iptccat:a']), |
| 207 | + ).toEqual(['paCat:a']); |
| 208 | + }); |
| 209 | + |
| 210 | + it('should return simple codes labelled "iptccat" as simple "paCat" codes', () => { |
| 211 | + expect( |
| 212 | + processFingerpostPACategoryCodes(['iptccat:a', 'iptccat:b']), |
| 213 | + ).toEqual(['paCat:a', 'paCat:b']); |
| 214 | + }); |
| 215 | + |
| 216 | + it('should expand category codes with multiple subcodes', () => { |
| 217 | + expect(processFingerpostPACategoryCodes(['iptccat:c+d'])).toEqual([ |
| 218 | + 'paCat:c', |
| 219 | + 'paCat:d', |
| 220 | + ]); |
| 221 | + }); |
| 222 | + |
| 223 | + it('should remove empty strings', () => { |
| 224 | + expect( |
| 225 | + processFingerpostPACategoryCodes(['iptccat:a', '', 'iptccat:c']), |
| 226 | + ).toEqual(['paCat:a', 'paCat:c']); |
| 227 | + }); |
| 228 | + |
| 229 | + it('should remove trailing and leading whitespace', () => { |
| 230 | + expect( |
| 231 | + processFingerpostPACategoryCodes([ |
| 232 | + 'iptccat:a ', |
| 233 | + ' iptccat:c', |
| 234 | + ' service:news ', |
| 235 | + 'qCode:value ', |
| 236 | + 'iptccat: ', |
| 237 | + ]), |
| 238 | + ).toEqual(['paCat:a', 'paCat:c', 'qCode:value']); |
| 239 | + }); |
| 240 | + |
| 241 | + it('should deduplicate category codes after stripping whitespace', () => { |
| 242 | + expect( |
| 243 | + processFingerpostPACategoryCodes([ |
| 244 | + 'iptccat:a ', |
| 245 | + ' iptccat:a', |
| 246 | + 'iptccat:c', |
| 247 | + ]), |
| 248 | + ).toEqual(['paCat:a', 'paCat:c']); |
| 249 | + }); |
| 250 | + |
| 251 | + it('should return original codes unchanged if they are not prefixed with "iptccat" or "service"', () => { |
| 252 | + expect( |
| 253 | + processFingerpostPACategoryCodes([ |
| 254 | + 'sport', |
| 255 | + 'sport:uk', |
| 256 | + 'paCat:sport:uk', |
| 257 | + ]), |
| 258 | + ).toEqual(['sport', 'sport:uk', 'paCat:sport:uk']); |
| 259 | + }); |
208 | 260 | }); |
| 261 | + }); |
209 | 262 |
|
210 | | - it('should return simple codes labelled "iptccat" as simple "paCat" codes', () => { |
| 263 | + describe('when mediaCatCodes is provided', () => { |
| 264 | + it('should append the mediaCatCode to the processed category codes', () => { |
211 | 265 | expect( |
212 | | - processFingerpostPACategoryCodes(['iptccat:a', 'iptccat:b']), |
213 | | - ).toEqual(['paCat:a', 'paCat:b']); |
| 266 | + processFingerpostPACategoryCodes(['iptccat:a'], 'exampleCategory'), |
| 267 | + ).toEqual(['paCat:a', 'paCat:exampleCategory']); |
214 | 268 | }); |
215 | 269 |
|
216 | | - it('should expand category codes with multiple subcodes', () => { |
217 | | - expect(processFingerpostPACategoryCodes(['iptccat:c+d'])).toEqual([ |
218 | | - 'paCat:c', |
219 | | - 'paCat:d', |
| 270 | + it('should return only the mediaCatCode if no other category codes are provided', () => { |
| 271 | + expect(processFingerpostPACategoryCodes([], 'exampleCategory')).toEqual([ |
| 272 | + 'paCat:exampleCategory', |
220 | 273 | ]); |
221 | 274 | }); |
222 | 275 |
|
223 | | - it('should remove empty strings', () => { |
224 | | - expect( |
225 | | - processFingerpostPACategoryCodes(['iptccat:a', '', 'iptccat:c']), |
226 | | - ).toEqual(['paCat:a', 'paCat:c']); |
| 276 | + it('should return an empty array if no category codes or mediaCatCode are provided', () => { |
| 277 | + expect(processFingerpostPACategoryCodes([], undefined)).toEqual([]); |
| 278 | + expect(processFingerpostPACategoryCodes([], '')).toEqual([]); |
| 279 | + expect(processFingerpostPACategoryCodes([], ' ')).toEqual([]); |
227 | 280 | }); |
228 | | - |
229 | | - it('should remove trailing and leading whitespace', () => { |
230 | | - expect( |
231 | | - processFingerpostPACategoryCodes([ |
232 | | - 'iptccat:a ', |
233 | | - ' iptccat:c', |
234 | | - ' service:news ', |
235 | | - 'qCode:value ', |
236 | | - 'iptccat: ', |
237 | | - ]), |
238 | | - ).toEqual(['paCat:a', 'paCat:c', 'qCode:value']); |
239 | | - }); |
240 | | - |
241 | | - it('should deduplicate category codes after stripping whitespace', () => { |
242 | | - expect( |
243 | | - processFingerpostPACategoryCodes([ |
244 | | - 'iptccat:a ', |
245 | | - ' iptccat:a', |
246 | | - 'iptccat:c', |
247 | | - ]), |
248 | | - ).toEqual(['paCat:a', 'paCat:c']); |
249 | | - }); |
250 | | - }); |
251 | | -}); |
252 | | - |
253 | | -describe('processFingerpostPAAPICategoryCodes', () => { |
254 | | - it('should return an empty array if provided with an empty array', () => { |
255 | | - expect(processFingerpostPAAPICategoryCodes([])).toEqual([]); |
256 | | - }); |
257 | | - it('should append paCat if mediaCatCode is defined', () => { |
258 | | - expect(processFingerpostPAAPICategoryCodes([], 'exampleCategory')).toEqual([ |
259 | | - 'paCat:exampleCategory', |
260 | | - ]); |
261 | | - }); |
262 | | - it('should return the array unchanged if original category codes are supplied', () => { |
263 | | - expect(processFingerpostPAAPICategoryCodes(['hello', 'world'])).toEqual([ |
264 | | - 'hello', |
265 | | - 'world', |
266 | | - ]); |
267 | 281 | }); |
268 | 282 | }); |
269 | 283 |
|
|
0 commit comments