@@ -6,13 +6,20 @@ import APIError from '../src/error';
66
77const matcher = '*' ;
88
9- const ResponseGood = new Response (
9+ const Response200 = new Response (
1010 JSON . stringify ( { sample : 'data' } ) ,
1111 {
1212 status : 200
1313 }
1414) ;
1515
16+ const Response201 = new Response (
17+ null ,
18+ {
19+ status : 201
20+ }
21+ ) ;
22+
1623const Response400 = new Response (
1724 JSON . stringify ( { sample : 'not found' } ) ,
1825 {
@@ -43,14 +50,23 @@ test.serial('default params', async t => {
4350} ) ;
4451
4552test . serial ( '200 reponse' , async t => {
46- fetchMock . get ( matcher , ResponseGood ) ;
53+ fetchMock . get ( matcher , Response200 ) ;
4754 const result = await callAPIMethod ( ) ;
4855
4956 t . deepEqual ( result , { sample : 'data' } , 'correct response body' ) ;
5057
5158 fetchMock . restore ( ) ;
5259} ) ;
5360
61+ test . serial ( '201 reponse' , async t => {
62+ fetchMock . get ( matcher , Response201 ) ;
63+ const result = await callAPIMethod ( ) ;
64+
65+ t . is ( result , null , 'correct response body' ) ;
66+
67+ fetchMock . restore ( ) ;
68+ } ) ;
69+
5470test . serial ( '400 reponse' , async t => {
5571 fetchMock . get ( matcher , Response400 ) ;
5672
@@ -74,7 +90,7 @@ test.serial('500 reponse', async t => {
7490} ) ;
7591
7692test . serial ( 'fetch options' , async t => {
77- fetchMock . post ( matcher , ResponseGood ) ;
93+ fetchMock . post ( matcher , Response200 ) ;
7894
7995 const APINamespace = 'rest-api' ;
8096 const namespace = 'user' ;
@@ -87,7 +103,7 @@ test.serial('fetch options', async t => {
87103 } ,
88104 method : 'text'
89105 } ;
90- const spyResponseGood = sinon . spy ( ResponseGood , 'text' ) ;
106+ const spyResponse200 = sinon . spy ( Response200 , 'text' ) ;
91107
92108 fetchMock . post ( matcher , { } ) ;
93109
@@ -100,14 +116,14 @@ test.serial('fetch options', async t => {
100116 method : 'POST' ,
101117 mode : 'cors'
102118 } , 'correct options' ) ;
103- t . true ( spyResponseGood . calledOnce ) ;
119+ t . true ( spyResponse200 . calledOnce ) ;
104120
105- spyResponseGood . restore ( ) ;
121+ spyResponse200 . restore ( ) ;
106122 fetchMock . restore ( ) ;
107123} ) ;
108124
109125test . serial ( 'unsupported Response method' , async t => {
110- fetchMock . get ( matcher , ResponseGood ) ;
126+ fetchMock . get ( matcher , Response200 ) ;
111127
112128 const APINamespace = 'rest-api' ;
113129 const namespace = 'user' ;
0 commit comments