-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmdb-api-tests.json
More file actions
1381 lines (1381 loc) · 64.8 KB
/
tmdb-api-tests.json
File metadata and controls
1381 lines (1381 loc) · 64.8 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"info": {
"_postman_id": "13c47a62-68b3-49ca-9fb0-49d12c833d36",
"name": "TMDB Portfolio",
"description": "Postman test collection for The Movie Database (TMDB) API. Tests movie and TV popular list and detail page endpoints covering schema validation, pagination metadata, date format, ISO format validation, data integrity checks, chained requests using dynamically captured IDs, and response time. See README for full details.\n\n \n[https://github.com/Alianin/api-testing-portfolio](https://github.com/Alianin/api-testing-portfolio)",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "51474602",
"_collection_link": "https://go.postman.co/collection/51474602-13c47a62-68b3-49ca-9fb0-49d12c833d36?source=collection_link"
},
"item": [
{
"name": "Authentication",
"item": [
{
"name": "Valid auth",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// -----------------------------\r",
"// GET FOLDER VARIABLES\r",
"// -----------------------------\r",
"const jsonData = JSON.parse(pm.variables.get(\"jsonData\"));\r",
"const schemaFailures = JSON.parse(pm.variables.get(\"schemaFailures\"));\r",
"\r",
"// -----------------------------\r",
"// TESTS\r",
"// -----------------------------\r",
"pm.test(\"Status code is 200\", () => {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Response is JSON\", () => {\r",
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");\r",
"});\r",
"pm.test(\"All items match expected schema\", () => {\r",
" const failureSummary = schemaFailures.map(f =>\r",
" f.errors.map(e => e.message).join(\",\")\r",
" ).join(\" | \");\r",
" pm.expect(schemaFailures.length, failureSummary).to.eql(0);\r",
"});\r",
"pm.test(\"Success is true\", () => {\r",
" pm.expect(jsonData.success).to.eql(true);\r",
"});\r",
"pm.test(\"Response time is acceptable\", () => {\r",
" pm.expect(pm.response.responseTime).to.be.below(500);\r",
"})"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/authentication",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"authentication"
]
},
"description": "Validates that a valid access token is accepted and returns a success response.\n\nAPI docs: [https://developer.themoviedb.org/reference/authentication-validate-key](https://developer.themoviedb.org/reference/authentication-validate-key)"
},
"response": []
},
{
"name": "Invalid auth",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.headers.upsert({\r",
" key: \"Authorization\",\r",
" value: \"Bearer invalid_token\"\r",
"});"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
},
{
"listen": "test",
"script": {
"exec": [
"// -----------------------------\r",
"// GET FOLDER VARIABLES\r",
"// -----------------------------\r",
"const jsonData = JSON.parse(pm.variables.get(\"jsonData\"));\r",
"const schemaFailures = JSON.parse(pm.variables.get(\"schemaFailures\"));\r",
"\r",
"// -----------------------------\r",
"// TESTS\r",
"// -----------------------------\r",
"pm.test(\"Status code is 401 Unauthorized\", () => {\r",
" pm.response.to.have.status(401);\r",
"});\r",
"pm.test(\"Response is JSON\", () => {\r",
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");\r",
"});\r",
"pm.test(\"All items match expected schema\", () => {\r",
" const failureSummary = schemaFailures.map(f =>\r",
" f.errors.map(e => e.message).join(\",\")\r",
" ).join(\" | \");\r",
" pm.expect(schemaFailures.length, failureSummary).to.eql(0);\r",
"});\r",
"pm.test(\"Success is false\", () => {\r",
" pm.expect(jsonData.success).to.eql(false);\r",
"});\r",
"pm.test(\"Response time is acceptable\", () => {\r",
" pm.expect(pm.response.responseTime).to.be.below(500);\r",
"})"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/authentication",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"authentication"
]
},
"description": "Validates that an invalid access token is rejected and returns an unauthorized response.\n\nAPI docs: [https://developer.themoviedb.org/reference/authentication-validate-key](https://developer.themoviedb.org/reference/authentication-validate-key)"
},
"response": []
}
],
"description": "Tests the authentication endpoint covering schema validation, success state, and response time for both valid and invalid credentials.",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
"const Ajv = require('ajv');\r",
"const ajv = new Ajv({ allErrors: true });\r",
"\r",
"// -----------------------------\r",
"// AUTH SCHEMA DEFINITION\r",
"// -----------------------------\r",
"const authSchema = {\r",
" type: \"object\",\r",
" required: [\"success\"],\r",
" properties: {\r",
" success: {type: \"boolean\"}\r",
" }\r",
"};\r",
"\r",
"// -----------------------------\r",
"// PARSE RESPONSE\r",
"// -----------------------------\r",
"const jsonData = pm.response.json();\r",
"\r",
"// -----------------------------\r",
"// VALIDATION\r",
"// -----------------------------\r",
"const validateResult = ajv.compile(authSchema);\r",
"const validSchema = validateResult(jsonData);\r",
"\r",
"let schemaFailures = [];\r",
"\r",
"if (!validSchema) {\r",
" schemaFailures.push({\r",
" errors: validateResult.errors\r",
" });\r",
"};\r",
"\r",
"// -----------------------------\r",
"// STORE DATA FOR REQUEST SCRIPTS\r",
"// -----------------------------\r",
"pm.variables.set(\"jsonData\", JSON.stringify(jsonData));\r",
"pm.variables.set(\"schemaFailures\", JSON.stringify(schemaFailures));\r",
"\r",
"// -----------------------------\r",
"// DEBUG LOGGING\r",
"// -----------------------------\r",
"console.log(`Auth test summary`);\r",
"console.log(\"Schema failures:\", schemaFailures);"
]
}
}
]
},
{
"name": "Popular lists",
"item": [
{
"name": "Popular movie list",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.variables.set(\"listName\", \"movie\");"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/movie/popular",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"movie",
"popular"
]
},
"description": "Returns a paginated list of popular movies. Validates schema, pagination metadata, date formats, and duplicate IDs. Captures the first movie ID for use in the Movie detail request.\n\nAPI docs: [https://developer.themoviedb.org/reference/movie-popular-list](https://developer.themoviedb.org/reference/movie-popular-list)"
},
"response": []
},
{
"name": "Popular TV show list",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"pm.variables.set(\"listName\", \"tv\");"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/tv/popular",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"tv",
"popular"
]
},
"description": "Returns a paginated list of popular TV shows. Validates schema, pagination metadata, date formats, and duplicate IDs. Captures the first TV show ID for use in the TV detail request.\n\nAPI docs: [https://developer.themoviedb.org/reference/tv-series-popular-list](https://developer.themoviedb.org/reference/tv-series-popular-list)"
},
"response": []
}
],
"description": "Tests the movie and TV popular list endpoints covering schema validation, pagination metadata, date format, duplicate detection, response time, and ID capture for detail request chaining.",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
"const Ajv = require('ajv');\r",
"const ajv = new Ajv({ allErrors: true });\r",
"\r",
"// -----------------------------\r",
"// LIST SCHEMA DEFINITIONS\r",
"// -----------------------------\r",
"const listSchemas = {\r",
"\tmovie: {\r",
"\t\ttype: \"object\",\r",
"\t\trequired: [\"adult\", \"id\", \"original_language\", \"original_title\", \"overview\", \"popularity\", \"release_date\", \"title\", \"video\", \"vote_average\", \"vote_count\"],\r",
"\t\tproperties: {\r",
" adult: {type: \"boolean\"},\r",
" backdrop_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" genre_ids: {type: \"array\", items: {type: \"integer\"}},\r",
"\t\t\tid: {type: \"integer\", minimum: 1},\r",
" original_language: {type: \"string\"},\r",
" original_title: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" popularity: {type: \"number\", minimum: 0},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" release_date: {type: \"string\"},\r",
" title: {type: \"string\", minLength: 1},\r",
" video: {type: \"boolean\"},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0}\r",
"\t\t}\r",
"\t},\r",
" tv: {\r",
"\t\ttype: \"object\",\r",
"\t\trequired: [\"adult\", \"id\", \"origin_country\", \"original_language\", \"original_name\", \"overview\", \"popularity\", \"first_air_date\", \"name\", \"vote_average\", \"vote_count\"],\r",
"\t\tproperties: {\r",
" adult: {type: \"boolean\"},\r",
" backdrop_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" genre_ids: {type: \"array\", items: {type: \"integer\"}},\r",
"\t\t\tid: {type: \"integer\", minimum: 1},\r",
" origin_country: {type: \"array\", items: {type: \"string\"}, minItems: 1},\r",
" original_language: {type: \"string\"},\r",
" original_name: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" popularity: {type: \"number\", minimum: 0},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" first_air_date: {type: \"string\"},\r",
" name: {type: \"string\", minLength: 1},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0}\r",
"\t\t}\r",
"\t}\r",
"}\r",
"\r",
"// -----------------------------\r",
"// DETERMINE LIST TYPE\r",
"// -----------------------------\r",
"const listName = pm.variables.get(\"listName\");\r",
"\r",
"if (!listSchemas[listName]) {\r",
" throw new Error(`No schema defined for list \"${listName}\"`);\r",
"}\r",
"\r",
"const listSchema = listSchemas[listName];\r",
"const validateResult = ajv.compile(listSchema);\r",
"\r",
"// -----------------------------\r",
"// PARSE RESPONSE\r",
"// -----------------------------\r",
"const jsonData = pm.response.json();\r",
"const dataResults = jsonData.results || [];\r",
"\r",
"// -----------------------------\r",
"// TRACKING & REGEX VARIABLES\r",
"// -----------------------------\r",
"let totalResults = dataResults.length;\r",
"let schemaFailures = [];\r",
"let dateFailures = [];\r",
"let duplicateIds = [];\r",
"let idsSeen = new Set();\r",
"\r",
"const iso8601Regex = /^\\d{4}-\\d{2}-\\d{2}$/;\r",
"\r",
"// -----------------------------\r",
"// VALIDATION LOOP\r",
"// -----------------------------\r",
"dataResults.forEach(result => {\r",
"\r",
" // Schema checks\r",
" const validSchema = validateResult(result);\r",
" if (!validSchema) {\r",
" schemaFailures.push({\r",
" id: result.id,\r",
" errors: validateResult.errors\r",
" });\r",
" }\r",
"\r",
" // Date validation\r",
" [\"release_date\", \"first_air_date\"].forEach(field => {\r",
" if (result[field] && !iso8601Regex.test(result[field])) {\r",
" dateFailures.push(`${result.id} - ${field}: ${result[field]}`);\r",
" }\r",
" });\r",
"\r",
" // Duplicate detection\r",
" if (idsSeen.has(result.id)) {\r",
" duplicateIds.push(result.id);\r",
" }\r",
"\r",
" idsSeen.add(result.id);\r",
"});\r",
"\r",
"// Store IDs to be used in chained request tests\r",
"if (listName === \"movie\") {\r",
" pm.collectionVariables.set(\"movieId\", dataResults[0].id);\r",
"} else if (listName === \"tv\") {\r",
" pm.collectionVariables.set(\"tvId\", dataResults[0].id);\r",
"}\r",
"\r",
"// -----------------------------\r",
"// TESTS\r",
"// -----------------------------\r",
"pm.test(\"Status code is 200\", () => {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Response is JSON\", () => {\r",
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");\r",
"});\r",
"pm.test(\"Page defaults to 1\", () => {\r",
" pm.expect(jsonData.page).to.eql(1);\r",
"});\r",
"pm.test(\"Total pages is greater than zero\", () => {\r",
" pm.expect(jsonData.total_pages).to.be.above(0);\r",
"});\r",
"pm.test(\"Response contains results\", () => {\r",
" pm.expect(jsonData.results.length).to.be.above(0);\r",
"});\r",
"pm.test(\"Total results is greater than zero\", () => {\r",
" pm.expect(jsonData.total_results).to.be.above(0);\r",
"});\r",
"pm.test(\"Total results is greater than or equal to results\", () => {\r",
" pm.expect(jsonData.total_results).to.be.gte(jsonData.results.length);\r",
"});\r",
"pm.test(\"No duplicate IDs in list results\", () => {\r",
" pm.expect(duplicateIds.length).to.eql(0);\r",
"});\r",
"pm.test(\"All objects match expected schema\", () => {\r",
" const failureSummary = schemaFailures.map(f =>\r",
" `ID ${f.id}: ${f.errors.map(e => e.message).join(\",\")}`\r",
" ).join(\" | \");\r",
" pm.expect(schemaFailures.length, failureSummary).to.eql(0);\r",
"});\r",
"pm.test(\"All date fields are valid ISO 8601 format\", () => {\r",
" pm.expect(dateFailures.length).to.eql(0);\r",
"});\r",
"pm.test(\"Response time is acceptable\", () => {\r",
" pm.expect(pm.response.responseTime).to.be.below(500);\r",
"});\r",
"\r",
"// -----------------------------\r",
"// DEBUG LOGGING\r",
"// -----------------------------\r",
"console.log(`List test summary for ${listName}`);\r",
"console.log(\"Results:\", totalResults);\r",
"console.log(\"Schema failures:\", schemaFailures);\r",
"console.log(\"Date failures\", dateFailures);\r",
"console.log(\"Duplicate IDs:\", duplicateIds);"
]
}
}
]
},
{
"name": "Page detail",
"item": [
{
"name": "Movie detail",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"const movieId = pm.collectionVariables.get(\"movieId\");\r",
"if (!movieId) { // Ensure that the movieId exists since the API call requires an ID\r",
" throw new Error(\"movieId not set — run the Popular Lists requests first\");\r",
"}\r",
"pm.variables.set(\"detailName\", \"movie\");"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/movie/{{movieId}}",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"movie",
"{{movieId}}"
]
},
"description": "Returns full details for a movie. ID is dynamically captured from the Movie popular list request. Validates schema, date formats, ISO country and language codes, and response ID consistency.\n\nAPI docs: [https://developer.themoviedb.org/reference/movie-details](https://developer.themoviedb.org/reference/movie-details)"
},
"response": []
},
{
"name": "TV detail",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"const tvId = pm.collectionVariables.get(\"tvId\");\r",
"if (!tvId) { // Ensure that the tvId exists since the API call requires an ID\r",
" throw new Error(\"tvId not set — run the Popular lists requests first\");\r",
"}\r",
"pm.variables.set(\"detailName\", \"tv\");"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.themoviedb.org/3/tv/{{tvId}}",
"protocol": "https",
"host": [
"api",
"themoviedb",
"org"
],
"path": [
"3",
"tv",
"{{tvId}}"
]
},
"description": "Returns full details for a TV show. ID is dynamically captured from the TV popular list request. Validates schema, date formats, ISO codes, season count consistency, episode/season ratio, and that ended shows have no next episode scheduled.\n\nAPI docs: [https://developer.themoviedb.org/reference/tv-series-details](https://developer.themoviedb.org/reference/tv-series-details)"
},
"response": []
}
],
"description": "Tests the movie and TV detail page endpoints covering schema validation, date format, ISO format validation on country and language codes, data integrity checks (season count consistency, episode/season ratio, ended shows without next episodes), response ID verification, and response time. Chained from Popular lists using dynamically captured IDs.",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"requests": {},
"exec": [
"const Ajv = require('ajv');\r",
"const ajv = new Ajv({ allErrors: true });\r",
"\r",
"// -----------------------------\r",
"// DETAIL SCHEMA DEFINITIONS\r",
"// -----------------------------\r",
"const detailSchemas = {\r",
"\tmovie: {\r",
"\t\ttype: \"object\",\r",
"\t\trequired: [\"adult\", \"id\", \"original_language\", \"original_title\", \"overview\", \"popularity\", \"release_date\", \"title\", \"video\", \"vote_average\", \"vote_count\"],\r",
"\t\tproperties: {\r",
" adult: {type: \"boolean\"},\r",
" backdrop_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" belongs_to_collection: {\r",
" oneOf: [\r",
" {type: \"null\"}, // Not documented to allow null, but an observed response\r",
" {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\"},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" backdrop_path: {type: [\"string\", \"null\"]} // Not documented to allow null, but an observed response\r",
" }\r",
" }\r",
" ]\r",
" },\r",
" budget: {type: \"integer\", minimum: 0},\r",
" genres: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" homepage: {type: \"string\"},\r",
"\t\t\tid: {type: \"integer\", minimum: 1},\r",
" imdb_id: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" original_language: {type: \"string\"},\r",
" original_title: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" popularity: {type: \"number\", minimum: 0},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" production_companies: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\", \"origin_country\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" logo_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" name: {type: \"string\", minLength: 1},\r",
" origin_country: {type: \"string\"}\r",
" }\r",
" }\r",
" },\r",
" production_countries: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"iso_3166_1\", \"name\"],\r",
" properties: {\r",
" iso_3166_1: {type: \"string\", pattern: \"^[A-Z]{2}$\"},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" release_date: {type: \"string\"},\r",
" revenue: {type: \"integer\", minimum: 0},\r",
" runtime: {type: \"integer\", minimum: 1},\r",
" spoken_languages: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"english_name\", \"iso_639_1\", \"name\"],\r",
" properties: {\r",
" english_name: {type: \"string\", minLength: 1},\r",
" iso_639_1: {type: \"string\", pattern: \"^[a-z]{2}$\"},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" status: {type: \"string\", minLength: 1},\r",
" tagline: {type: \"string\"},\r",
" title: {type: \"string\", minLength: 1},\r",
" video: {type: \"boolean\"},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0}\r",
"\t\t}\r",
"\t},\r",
" tv: {\r",
" type: \"object\",\r",
" required: [\"adult\", \"first_air_date\", \"id\", \"in_production\", \"name\", \"number_of_episodes\", \"number_of_seasons\", \"original_language\", \"original_name\", \"overview\", \"popularity\", \"status\", \"vote_average\", \"vote_count\"],\r",
" properties: {\r",
" adult: {type: \"boolean\"},\r",
" backdrop_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" created_by: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\", \"gender\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" credit_id: {type: \"string\"},\r",
" name: {type: \"string\", minLength: 1},\r",
" original_name: {type: \"string\"}, // Undocumented property\r",
" gender: {type: \"integer\", minimum: 0},\r",
" profile_path: {type: [\"string\", \"null\"]} // Not documented to allow null, but an observed response\r",
" }\r",
" }\r",
" },\r",
" episode_run_time: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"integer\"\r",
" }\r",
" },\r",
" first_air_date: {type: \"string\"},\r",
" genres: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" homepage: {type: \"string\"},\r",
" id: {type: \"integer\", minimum: 1},\r",
" in_production: {type: \"boolean\"},\r",
" languages: {\r",
" type: \"array\",\r",
" items: {type: \"string\"}\r",
" },\r",
" last_air_date: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" last_episode_to_air: {\r",
" oneOf: [\r",
" {type: \"null\"}, // Not documented to allow null, but an observed response\r",
" {\r",
" type: \"object\",\r",
" required: [\"id\", \"vote_average\", \"vote_count\", \"episode_number\", \"runtime\", \"season_number\", \"show_id\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0},\r",
" air_date: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" episode_number: {type: \"integer\", minimum: 0},\r",
" episode_type: {type: \"string\"}, // Undocumented property\r",
" production_code: {type: \"string\"},\r",
" runtime: {type: [\"integer\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" season_number: {type: \"integer\", minimum: 0},\r",
" show_id: {type: \"integer\", minimum: 1},\r",
" still_path: {type: [\"string\", \"null\"]} // Not documented to allow null, but an observed response\r",
" }\r",
" }\r",
" ]\r",
" },\r",
" name: {type: \"string\", minLength: 1},\r",
" next_episode_to_air: {\r",
" oneOf: [ // Documented as a string, but observed to return null or an object\r",
" {type: \"null\"}, // Not documented to allow null, but an observed response\r",
" {\r",
" type: \"object\",\r",
" required: [\"id\", \"vote_average\", \"vote_count\", \"episode_number\", \"runtime\", \"season_number\", \"show_id\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0},\r",
" air_date: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" episode_number: {type: \"integer\", minimum: 0},\r",
" episode_type: {type: \"string\"}, // Undocumented property\r",
" production_code: {type: \"string\"},\r",
" runtime: {type: [\"integer\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" season_number: {type: \"integer\", minimum: 0},\r",
" show_id: {type: \"integer\", minimum: 1},\r",
" still_path: {type: [\"string\", \"null\"]} // Not documented to allow null, but an observed response\r",
" }\r",
" }\r",
" ]\r",
" },\r",
" networks: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" logo_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" name: {type: \"string\", minLength: 1},\r",
" origin_country: {type: \"string\"}\r",
" }\r",
" }\r",
" },\r",
" number_of_episodes: {type: \"integer\", minimum: 0},\r",
" number_of_seasons: {type: \"integer\", minimum: 0},\r",
" origin_country: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"string\"\r",
" }\r",
" },\r",
" original_language: {type: \"string\"},\r",
" original_name: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" popularity: {type: \"number\", minimum: 0},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" production_companies: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"id\", \"name\", \"origin_country\"],\r",
" properties: {\r",
" id: {type: \"integer\", minimum: 1},\r",
" logo_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" name: {type: \"string\", minLength: 1},\r",
" origin_country: {type: \"string\"}\r",
" }\r",
" }\r",
" },\r",
" production_countries: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"iso_3166_1\", \"name\"],\r",
" properties: {\r",
" iso_3166_1: {type: \"string\", pattern: \"^[A-Z]{2}$\"},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" seasons: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"episode_count\", \"id\", \"name\", \"season_number\", \"vote_average\"],\r",
" properties: {\r",
" air_date: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" episode_count: {type: \"integer\", minimum: 0},\r",
" id: {type: \"integer\", minimum: 1},\r",
" name: {type: \"string\", minLength: 1},\r",
" overview: {type: \"string\"},\r",
" poster_path: {type: [\"string\", \"null\"]}, // Not documented to allow null, but an observed response\r",
" season_number: {type: \"integer\", minimum: 0},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10} // Documented as integer, but returns number\r",
" }\r",
" }\r",
" },\r",
" spoken_languages: {\r",
" type: \"array\",\r",
" items: {\r",
" type: \"object\",\r",
" required: [\"english_name\", \"iso_639_1\", \"name\"],\r",
" properties: {\r",
" english_name: {type: \"string\", minLength: 1},\r",
" iso_639_1: {type: \"string\", pattern: \"^[a-z]{2}$\"},\r",
" name: {type: \"string\", minLength: 1}\r",
" }\r",
" }\r",
" },\r",
" status: {type: \"string\", minLength: 1},\r",
" tagline: {type: \"string\"},\r",
" type: {type: \"string\", minLength: 1},\r",
" vote_average: {type: \"number\", minimum: 0, maximum: 10},\r",
" vote_count: {type: \"integer\", minimum: 0}\r",
" }\r",
" }\r",
"}\r",
"\r",
"// -----------------------------\r",
"// DETERMINE DETAIL TYPE\r",
"// -----------------------------\r",
"const detailName = pm.variables.get(\"detailName\");\r",
"\r",
"if (!detailSchemas[detailName]) {\r",
" throw new Error(`No schema defined for detail \"${detailName}\"`);\r",
"}\r",
"\r",
"const detailSchema = detailSchemas[detailName];\r",
"const validateResult = ajv.compile(detailSchema);\r",
"\r",
"const isMovie = detailName === \"movie\";\r",
"const isTv = detailName === \"tv\";\r",
"\r",
"// -----------------------------\r",
"// PARSE RESPONSE\r",
"// -----------------------------\r",
"const jsonData = pm.response.json();\r",
"\r",
"// -----------------------------\r",
"// TRACKING & REGEX VARIABLES\r",
"// -----------------------------\r",
"let schemaFailures = [];\r",
"let dateFailures = [];\r",
"\r",
"const iso8601Regex = /^\\d{4}-\\d{2}-\\d{2}$/;\r",
"\r",
"// -----------------------------\r",
"// VALIDATION\r",
"// -----------------------------\r",
"// Get stored ID\r",
"const expectedId = Number(pm.collectionVariables.get(\r",
" detailName === \"movie\" ? \"movieId\" : \"tvId\"\r",
"));\r",
"\r",
"// Schema checks\r",
"const validSchema = validateResult(jsonData);\r",
"if (!validSchema) {\r",
" schemaFailures.push({\r",
" detail: detailName,\r",
" errors: validateResult.errors\r",
" });\r",
"};\r",
"\r",
"// Date validation\r",
"const datesToCheck = [];\r",
"\r",
"if (isMovie) {\r",
" datesToCheck.push(\r",
" {field: \"release_date\", value: jsonData.release_date}\r",
" );\r",
"}\r",
"\r",
"if (isTv) {\r",
" datesToCheck.push(\r",
" {field: \"first_air_date\", value: jsonData.first_air_date},\r",
" {field: \"last_air_date\", value: jsonData.last_air_date},\r",
" {field: \"last_episode_to_air.air_date\", value: jsonData.last_episode_to_air?.air_date},\r",
" {field: \"next_episode_to_air.air_date\", value: jsonData.next_episode_to_air?.air_date}\r",
" );\r",
"\r",
" if (jsonData.seasons) {\r",
" jsonData.seasons.forEach((season, index) => {\r",
" if (season.air_date && !iso8601Regex.test(season.air_date)) {\r",
" dateFailures.push(`seasons[${index}].air_date: ${season.air_date}`);\r",
" }\r",
" });\r",
" }\r",
"}\r",
"\r",
"datesToCheck.forEach(({field, value}) => {\r",
" if (value && !iso8601Regex.test(value)) {\r",
" dateFailures.push(`${field}: ${value}`);\r",
" }\r",
"});\r",
"\r",
"// -----------------------------\r",
"// TESTS\r",
"// -----------------------------\r",
"pm.test(\"Status code is 200\", () => {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Response is JSON\", () => {\r",
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");\r",
"});\r",
"pm.test(\"Response ID matches requested ID\", () => {\r",
" pm.expect(jsonData.id).to.eql(expectedId);\r",
"});\r",
"pm.test(\"All items match expected schema\", () => {\r",
" const failureSummary = schemaFailures.map(f =>\r",
" `${f.detail}: ${f.errors.map(e => e.message).join(\",\")}`\r",
" ).join(\" | \");\r",
" pm.expect(schemaFailures.length, failureSummary).to.eql(0);\r",
"});\r",
"pm.test(\"All date fields are valid ISO 8601 format\", () => {\r",
" pm.expect(dateFailures.length).to.eql(0);\r",
"});\r",
"if (isTv) {\r",
" pm.test(\"Number of seasons matches seasons list\", () => {\r",
" const specialsCount = jsonData.seasons.filter(s => s.season_number === 0).length;\r",
" pm.expect(jsonData.number_of_seasons).to.eql(jsonData.seasons.length - specialsCount); // Number of seasons doesn't count specials\r",
" });\r",
" pm.test(\"Ended TV shows do not have a next episode\", () => {\r",
" if (!jsonData.in_production) {\r",
" pm.expect(jsonData.next_episode_to_air).to.be.null;\r",
" } else {\r",
" pm.expect(true).to.be.true; // Show is in production, test not applicable\r",
" }\r",
" });\r",
" pm.test(\"There are more episodes than seasons\", () => {\r",
" pm.expect(jsonData.number_of_episodes).to.be.gte(jsonData.number_of_seasons);\r",
" })\r",
"}\r",
"pm.test(\"Response time is acceptable\", () => {\r",
" pm.expect(pm.response.responseTime).to.be.below(500);\r",
"});\r",
"\r",
"// -----------------------------\r",
"// DEBUG LOGGING\r",
"// -----------------------------\r",