@@ -868,4 +868,68 @@ module('Mirage | Keywords', function(hooks) {
868
868
assert . equal ( responsePayload . meta . total , 25 ) ;
869
869
} ) ;
870
870
} ) ;
871
+
872
+ module ( 'GET /api/v1/crates/:id/downloads' , function ( ) {
873
+ test ( 'returns 404 for unknown crates' , async function ( assert ) {
874
+ let response = await fetch ( '/api/v1/crates/foo/downloads' ) ;
875
+ assert . equal ( response . status , 404 ) ;
876
+
877
+ let responsePayload = await response . json ( ) ;
878
+ assert . deepEqual ( responsePayload , { errors : [ { detail : 'Not Found' } ] } ) ;
879
+ } ) ;
880
+
881
+ test ( 'empty case' , async function ( assert ) {
882
+ this . server . create ( 'crate' , { name : 'rand' } ) ;
883
+
884
+ let response = await fetch ( '/api/v1/crates/rand/downloads' ) ;
885
+ assert . equal ( response . status , 200 ) ;
886
+
887
+ let responsePayload = await response . json ( ) ;
888
+ assert . deepEqual ( responsePayload , {
889
+ version_downloads : [ ] ,
890
+ meta : {
891
+ extra_downloads : [ ] ,
892
+ } ,
893
+ } ) ;
894
+ } ) ;
895
+
896
+ test ( 'returns a list of version downloads belonging to the specified crate version' , async function ( assert ) {
897
+ this . server . create ( 'crate' , { name : 'rand' } ) ;
898
+ let versions = this . server . createList ( 'version' , 2 , { crate : 'rand' } ) ;
899
+ this . server . create ( 'version-download' , { version : versions [ 0 ] . id , date : '2020-01-13' } ) ;
900
+ this . server . create ( 'version-download' , { version : versions [ 1 ] . id , date : '2020-01-14' } ) ;
901
+ this . server . create ( 'version-download' , { version : versions [ 1 ] . id , date : '2020-01-15' } ) ;
902
+
903
+ let response = await fetch ( '/api/v1/crates/rand/downloads' ) ;
904
+ assert . equal ( response . status , 200 ) ;
905
+
906
+ // TODO Remove the `id` properties from the response
907
+ let responsePayload = await response . json ( ) ;
908
+ assert . deepEqual ( responsePayload , {
909
+ version_downloads : [
910
+ {
911
+ id : '1' ,
912
+ date : '2020-01-13' ,
913
+ downloads : 9380 ,
914
+ version : '1' ,
915
+ } ,
916
+ {
917
+ id : '2' ,
918
+ date : '2020-01-14' ,
919
+ downloads : 16415 ,
920
+ version : '2' ,
921
+ } ,
922
+ {
923
+ id : '3' ,
924
+ date : '2020-01-15' ,
925
+ downloads : 23450 ,
926
+ version : '2' ,
927
+ } ,
928
+ ] ,
929
+ meta : {
930
+ extra_downloads : [ ] ,
931
+ } ,
932
+ } ) ;
933
+ } ) ;
934
+ } ) ;
871
935
} ) ;
0 commit comments