11import { Merlin } from "merlin" ;
22import parse from "../utils/args/parser.ts" ;
3- import type { ArgResult } from "./types.ts" ;
3+ import type { ArgsType } from ". ./types.ts" ;
44
55const test = new Merlin ( ) ;
66
77test . assertEqual ( "GET: api.github.com" , {
88 expect ( ) {
99 return parse ( [ "api.github.com" ] ) ;
1010 } ,
11- toBe ( ) : ArgResult {
11+ toBe ( ) : ArgsType {
1212 return {
13- url : "api.github.com" ,
14- method : "GET" ,
13+ data : {
14+ url : "api.github.com" ,
15+ method : "GET" ,
16+ } ,
17+ type : "request" ,
1518 } ;
1619 } ,
1720} ) ;
@@ -20,10 +23,13 @@ test.assertEqual("GET (explicit): api.github.com", {
2023 expect ( ) {
2124 return parse ( [ "GET" , "api.github.com" ] ) ;
2225 } ,
23- toBe ( ) : ArgResult {
26+ toBe ( ) : ArgsType {
2427 return {
25- method : "GET" ,
26- url : "api.github.com" ,
28+ data : {
29+ method : "GET" ,
30+ url : "api.github.com" ,
31+ } ,
32+ type : "request" ,
2733 } ;
2834 } ,
2935} ) ;
@@ -32,10 +38,13 @@ test.assertEqual("GET: complex url", {
3238 expect ( ) {
3339 return parse ( [ "localhost:8080/[pgk]/?id=20" ] ) ;
3440 } ,
35- toBe ( ) : ArgResult {
41+ toBe ( ) : ArgsType {
3642 return {
37- url : "localhost:8080/[pgk]/?id=20" ,
38- method : "GET" ,
43+ data : {
44+ url : "localhost:8080/[pgk]/?id=20" ,
45+ method : "GET" ,
46+ } ,
47+ type : "request" ,
3948 } ;
4049 } ,
4150} ) ;
@@ -44,12 +53,15 @@ test.assertEqual("POST: send a email", {
4453 expect ( ) {
4554 return parse ( [ "POST" , "localhost:8080" , "email=foo@bar.com" ] ) ;
4655 } ,
47- toBe ( ) : ArgResult {
56+ toBe ( ) : ArgsType {
4857 return {
49- method : "POST" ,
50- url : "localhost:8080" ,
51- headers : { "Content-Type" : "application/json" } ,
52- body : { email : "foo@bar.com" } ,
58+ data : {
59+ method : "POST" ,
60+ url : "localhost:8080" ,
61+ headers : { "content-type" : "application/json" } ,
62+ body : { email : "foo@bar.com" } ,
63+ } ,
64+ type : "request" ,
5365 } ;
5466 } ,
5567} ) ;
@@ -62,12 +74,15 @@ test.assertEqual("POST: send a url", {
6274 "url=http://localhost:8080/api/foo_bar" ,
6375 ] ) ;
6476 } ,
65- toBe ( ) : ArgResult {
77+ toBe ( ) : ArgsType {
6678 return {
67- method : "POST" ,
68- url : "localhost:8080" ,
69- headers : { "Content-Type" : "application/json" } ,
70- body : { url : "http://localhost:8080/api/foo_bar" } ,
79+ data : {
80+ method : "POST" ,
81+ url : "localhost:8080" ,
82+ headers : { "content-type" : "application/json" } ,
83+ body : { url : "http://localhost:8080/api/foo_bar" } ,
84+ } ,
85+ type : "request" ,
7186 } ;
7287 } ,
7388} ) ;
@@ -76,12 +91,15 @@ test.assertEqual("POST: multiple values", {
7691 expect ( ) {
7792 return parse ( [ "POST" , "localhost:8080" , "foo=bar" , "bar=foo" ] ) ;
7893 } ,
79- toBe ( ) : ArgResult {
94+ toBe ( ) : ArgsType {
8095 return {
81- method : "POST" ,
82- url : "localhost:8080" ,
83- headers : { "Content-Type" : "application/json" } ,
84- body : { foo : "bar" , bar : "foo" } ,
96+ data : {
97+ method : "POST" ,
98+ url : "localhost:8080" ,
99+ headers : { "content-type" : "application/json" } ,
100+ body : { foo : "bar" , bar : "foo" } ,
101+ } ,
102+ type : "request" ,
85103 } ;
86104 } ,
87105} ) ;
@@ -90,12 +108,15 @@ test.assertEqual("POST: value with spaces", {
90108 expect ( ) {
91109 return parse ( [ "POST" , "localhost:8080" , "foo=one bar" ] ) ;
92110 } ,
93- toBe ( ) : ArgResult {
111+ toBe ( ) : ArgsType {
94112 return {
95- method : "POST" ,
96- url : "localhost:8080" ,
97- headers : { "Content-Type" : "application/json" } ,
98- body : { foo : "one bar" } ,
113+ data : {
114+ method : "POST" ,
115+ url : "localhost:8080" ,
116+ headers : { "content-type" : "application/json" } ,
117+ body : { foo : "one bar" } ,
118+ } ,
119+ type : "request" ,
99120 } ;
100121 } ,
101122} ) ;
@@ -111,14 +132,17 @@ test.assertEqual("POST: with object and array", {
111132 "magic]}" ,
112133 ] ) ;
113134 } ,
114- toBe ( ) : ArgResult {
135+ toBe ( ) : ArgsType {
115136 return {
116- method : "POST" ,
117- url : "localhost:8080" ,
118- headers : { "Content-Type" : "application/json" } ,
119- body : {
120- person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
137+ data : {
138+ method : "POST" ,
139+ url : "localhost:8080" ,
140+ headers : { "content-type" : "application/json" } ,
141+ body : {
142+ person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
143+ } ,
121144 } ,
145+ type : "request" ,
122146 } ;
123147 } ,
124148} ) ;
@@ -134,14 +158,17 @@ test.assertEqual("PUT: with object and array", {
134158 "magic]}" ,
135159 ] ) ;
136160 } ,
137- toBe ( ) : ArgResult {
161+ toBe ( ) : ArgsType {
138162 return {
139- method : "PUT" ,
140- url : "localhost:8080" ,
141- headers : { "Content-Type" : "application/json" } ,
142- body : {
143- person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
163+ data : {
164+ method : "PUT" ,
165+ url : "localhost:8080" ,
166+ headers : { "content-type" : "application/json" } ,
167+ body : {
168+ person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
169+ } ,
144170 } ,
171+ type : "request" ,
145172 } ;
146173 } ,
147174} ) ;
@@ -157,14 +184,17 @@ test.assertEqual("PATCH: with object and array", {
157184 "magic]}" ,
158185 ] ) ;
159186 } ,
160- toBe ( ) : ArgResult {
187+ toBe ( ) : ArgsType {
161188 return {
162- method : "PATCH" ,
163- url : "localhost:8080" ,
164- headers : { "Content-Type" : "application/json" } ,
165- body : {
166- person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
189+ data : {
190+ method : "PATCH" ,
191+ url : "localhost:8080" ,
192+ headers : { "content-type" : "application/json" } ,
193+ body : {
194+ person : { name : "Deno Merlin" , age : 24 , hobbies : [ "test" , "magic" ] } ,
195+ } ,
167196 } ,
197+ type : "request" ,
168198 } ;
169199 } ,
170200} ) ;
@@ -173,10 +203,10 @@ test.assertEqual("DELETE", {
173203 expect ( ) {
174204 return parse ( [ "DELETE" , "localhost:8080" ] ) ;
175205 } ,
176- toBe ( ) : ArgResult {
206+ toBe ( ) : ArgsType {
177207 return {
178- method : "DELETE" ,
179- url : "localhost:8080 " ,
208+ data : { method : "DELETE" , url : "localhost:8080" } ,
209+ type : "request " ,
180210 } ;
181211 } ,
182212} ) ;
0 commit comments