@@ -104,6 +104,36 @@ void main() {
104
104
checkRequest (['asdf' .codeUnits], 100 , null );
105
105
});
106
106
107
+ test ('ApiConnection.delete' , () async {
108
+ Future <void > checkRequest (Map <String , dynamic >? params, String expectedBody, {bool expectContentType = true }) {
109
+ return FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
110
+ connection.prepare (json: {});
111
+ await connection.delete (kExampleRouteName, (json) => json, 'example/route' , params);
112
+ check (connection.lastRequest! ).isA< http.Request > ()
113
+ ..method.equals ('DELETE' )
114
+ ..url.asString.equals ('${eg .realmUrl .origin }/api/v1/example/route' )
115
+ ..headers.deepEquals ({
116
+ ...authHeader (email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey),
117
+ if (expectContentType)
118
+ 'content-type' : 'application/x-www-form-urlencoded; charset=utf-8' ,
119
+ })
120
+ ..body.equals (expectedBody);
121
+ });
122
+ }
123
+
124
+ checkRequest (null , '' , expectContentType: false );
125
+ checkRequest ({}, '' );
126
+ checkRequest ({'x' : 3 }, 'x=3' );
127
+ checkRequest ({'x' : 3 , 'y' : 4 }, 'x=3&y=4' );
128
+ checkRequest ({'x' : null }, 'x=null' );
129
+ checkRequest ({'x' : true }, 'x=true' );
130
+ checkRequest ({'x' : 'foo' }, 'x=%22foo%22' );
131
+ checkRequest ({'x' : [1 , 2 ]}, 'x=%5B1%2C2%5D' );
132
+ checkRequest ({'x' : {'y' : 1 }}, 'x=%7B%22y%22%3A1%7D' );
133
+ checkRequest ({'x' : RawParameter ('foo' )}, 'x=foo' );
134
+ checkRequest ({'x' : RawParameter ('foo' ), 'y' : 'bar' }, 'x=foo&y=%22bar%22' );
135
+ });
136
+
107
137
test ('API success result' , () async {
108
138
await FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
109
139
connection.prepare (json: {'result' : 'success' , 'x' : 3 });
0 commit comments