@@ -5,94 +5,92 @@ import fetch from 'fetch';
5
5
import { setupTest } from '../../helpers' ;
6
6
import setupMirage from '../../helpers/setup-mirage' ;
7
7
8
- module ( 'Mirage | Categories ' , function ( hooks ) {
8
+ module ( 'Mirage | GET /api/v1/categories ' , function ( hooks ) {
9
9
setupTest ( hooks ) ;
10
10
setupMirage ( hooks ) ;
11
11
12
- module ( 'GET /api/v1/categories' , function ( ) {
13
- test ( 'empty case' , async function ( assert ) {
14
- let response = await fetch ( '/api/v1/categories' ) ;
15
- assert . equal ( response . status , 200 ) ;
12
+ test ( 'empty case' , async function ( assert ) {
13
+ let response = await fetch ( '/api/v1/categories' ) ;
14
+ assert . equal ( response . status , 200 ) ;
16
15
17
- let responsePayload = await response . json ( ) ;
18
- assert . deepEqual ( responsePayload , {
19
- categories : [ ] ,
20
- meta : {
21
- total : 0 ,
22
- } ,
23
- } ) ;
16
+ let responsePayload = await response . json ( ) ;
17
+ assert . deepEqual ( responsePayload , {
18
+ categories : [ ] ,
19
+ meta : {
20
+ total : 0 ,
21
+ } ,
24
22
} ) ;
23
+ } ) ;
25
24
26
- test ( 'returns a paginated categories list' , async function ( assert ) {
27
- this . server . create ( 'category' , {
28
- category : 'no-std' ,
29
- description : 'Crates that are able to function without the Rust standard library.' ,
30
- } ) ;
31
- this . server . createList ( 'category' , 2 ) ;
25
+ test ( 'returns a paginated categories list' , async function ( assert ) {
26
+ this . server . create ( 'category' , {
27
+ category : 'no-std' ,
28
+ description : 'Crates that are able to function without the Rust standard library.' ,
29
+ } ) ;
30
+ this . server . createList ( 'category' , 2 ) ;
32
31
33
- let response = await fetch ( '/api/v1/categories' ) ;
34
- assert . equal ( response . status , 200 ) ;
32
+ let response = await fetch ( '/api/v1/categories' ) ;
33
+ assert . equal ( response . status , 200 ) ;
35
34
36
- let responsePayload = await response . json ( ) ;
37
- assert . deepEqual ( responsePayload , {
38
- categories : [
39
- {
40
- id : 'category-1' ,
41
- category : 'Category 1' ,
42
- crates_cnt : 0 ,
43
- created_at : '2010-06-16T21:30:45Z' ,
44
- description : 'This is the description for the category called "Category 1"' ,
45
- slug : 'category-1' ,
46
- } ,
47
- {
48
- id : 'category-2' ,
49
- category : 'Category 2' ,
50
- crates_cnt : 0 ,
51
- created_at : '2010-06-16T21:30:45Z' ,
52
- description : 'This is the description for the category called "Category 2"' ,
53
- slug : 'category-2' ,
54
- } ,
55
- {
56
- id : 'no-std' ,
57
- category : 'no-std' ,
58
- crates_cnt : 0 ,
59
- created_at : '2010-06-16T21:30:45Z' ,
60
- description : 'Crates that are able to function without the Rust standard library.' ,
61
- slug : 'no-std' ,
62
- } ,
63
- ] ,
64
- meta : {
65
- total : 3 ,
35
+ let responsePayload = await response . json ( ) ;
36
+ assert . deepEqual ( responsePayload , {
37
+ categories : [
38
+ {
39
+ id : 'category-1' ,
40
+ category : 'Category 1' ,
41
+ crates_cnt : 0 ,
42
+ created_at : '2010-06-16T21:30:45Z' ,
43
+ description : 'This is the description for the category called "Category 1"' ,
44
+ slug : 'category-1' ,
45
+ } ,
46
+ {
47
+ id : 'category-2' ,
48
+ category : 'Category 2' ,
49
+ crates_cnt : 0 ,
50
+ created_at : '2010-06-16T21:30:45Z' ,
51
+ description : 'This is the description for the category called "Category 2"' ,
52
+ slug : 'category-2' ,
53
+ } ,
54
+ {
55
+ id : 'no-std' ,
56
+ category : 'no-std' ,
57
+ crates_cnt : 0 ,
58
+ created_at : '2010-06-16T21:30:45Z' ,
59
+ description : 'Crates that are able to function without the Rust standard library.' ,
60
+ slug : 'no-std' ,
66
61
} ,
67
- } ) ;
62
+ ] ,
63
+ meta : {
64
+ total : 3 ,
65
+ } ,
68
66
} ) ;
67
+ } ) ;
69
68
70
- test ( 'never returns more than 10 results' , async function ( assert ) {
71
- this . server . createList ( 'category' , 25 ) ;
69
+ test ( 'never returns more than 10 results' , async function ( assert ) {
70
+ this . server . createList ( 'category' , 25 ) ;
72
71
73
- let response = await fetch ( '/api/v1/categories' ) ;
74
- assert . equal ( response . status , 200 ) ;
72
+ let response = await fetch ( '/api/v1/categories' ) ;
73
+ assert . equal ( response . status , 200 ) ;
75
74
76
- let responsePayload = await response . json ( ) ;
77
- assert . equal ( responsePayload . categories . length , 10 ) ;
78
- assert . equal ( responsePayload . meta . total , 25 ) ;
79
- } ) ;
75
+ let responsePayload = await response . json ( ) ;
76
+ assert . equal ( responsePayload . categories . length , 10 ) ;
77
+ assert . equal ( responsePayload . meta . total , 25 ) ;
78
+ } ) ;
80
79
81
- test ( 'supports `page` and `per_page` parameters' , async function ( assert ) {
82
- this . server . createList ( 'category' , 25 , {
83
- category : i => `cat-${ String ( i + 1 ) . padStart ( 2 , '0' ) } ` ,
84
- } ) ;
80
+ test ( 'supports `page` and `per_page` parameters' , async function ( assert ) {
81
+ this . server . createList ( 'category' , 25 , {
82
+ category : i => `cat-${ String ( i + 1 ) . padStart ( 2 , '0' ) } ` ,
83
+ } ) ;
85
84
86
- let response = await fetch ( '/api/v1/categories?page=2&per_page=5' ) ;
87
- assert . equal ( response . status , 200 ) ;
85
+ let response = await fetch ( '/api/v1/categories?page=2&per_page=5' ) ;
86
+ assert . equal ( response . status , 200 ) ;
88
87
89
- let responsePayload = await response . json ( ) ;
90
- assert . equal ( responsePayload . categories . length , 5 ) ;
91
- assert . deepEqual (
92
- responsePayload . categories . map ( it => it . id ) ,
93
- [ 'cat-06' , 'cat-07' , 'cat-08' , 'cat-09' , 'cat-10' ] ,
94
- ) ;
95
- assert . equal ( responsePayload . meta . total , 25 ) ;
96
- } ) ;
88
+ let responsePayload = await response . json ( ) ;
89
+ assert . equal ( responsePayload . categories . length , 5 ) ;
90
+ assert . deepEqual (
91
+ responsePayload . categories . map ( it => it . id ) ,
92
+ [ 'cat-06' , 'cat-07' , 'cat-08' , 'cat-09' , 'cat-10' ] ,
93
+ ) ;
94
+ assert . equal ( responsePayload . meta . total , 25 ) ;
97
95
} ) ;
98
96
} ) ;
0 commit comments