1
- import { Picker } from 'meteor/storyteller:picker' ;
2
- // TODO replace HTTP with fetch
3
- import { HTTP } from 'meteor/http' ;
4
- import { Random } from 'meteor/random' ;
5
- import { Meteor } from 'meteor/meteor' ;
1
+ import { Picker } from 'meteor/communitypackages:picker'
2
+ import { fetch } from 'meteor/fetch'
3
+ import { Meteor } from 'meteor/meteor'
4
+ import { Random } from 'meteor/random'
6
5
7
6
function getPath ( path ) {
8
7
return Meteor . absoluteUrl ( path ) ;
9
8
}
10
9
10
+ async function getAsync ( url , options ) {
11
+ try {
12
+ const response = await fetch ( url , options )
13
+ return await response . text ( )
14
+ } catch ( e ) {
15
+ throw new Meteor . Error ( 500 , e . message )
16
+ }
17
+ }
18
+
19
+ const get = Meteor . wrapAsync ( getAsync )
20
+
11
21
Tinytest . add ( 'normal route' , function ( test ) {
12
22
const id = Random . id ( ) ;
13
23
Picker . route ( `/${ id } ` , function ( params , req , res ) {
14
24
res . end ( "done" ) ;
15
25
} ) ;
16
26
17
- const res = HTTP . get ( getPath ( id ) ) ;
18
- test . equal ( res . content , 'done' ) ;
27
+ get ( getPath ( id ) , { method : 'GET' } , ( error , success ) => {
28
+ test . equal ( success , 'done' ) ;
29
+ } ) ;
30
+
19
31
} ) ;
20
32
21
33
Tinytest . add ( 'with params' , function ( test ) {
@@ -25,8 +37,9 @@ Tinytest.add('with params', function(test) {
25
37
res . end ( params . id ) ;
26
38
} ) ;
27
39
28
- const res = HTTP . get ( getPath ( `post/${ id } ` ) ) ;
29
- test . equal ( res . content , id ) ;
40
+ get ( getPath ( `post/${ id } ` ) , { method : 'GET' } , ( error , res ) => {
41
+ test . equal ( res , id ) ;
42
+ } ) ;
30
43
} ) ;
31
44
32
45
Tinytest . add ( 'filter only POST' , function ( test ) {
@@ -39,11 +52,15 @@ Tinytest.add('filter only POST', function(test) {
39
52
res . end ( "done" ) ;
40
53
} ) ;
41
54
42
- const res1 = HTTP . get ( getPath ( `/${ id } ` ) ) ;
43
- test . isFalse ( res1 . content === "done" ) ;
55
+ get ( getPath ( `/${ id } ` ) , { method : 'GET' } , ( error , res ) => {
56
+ test . isFalse ( res === "done" ) ;
57
+ } ) ;
58
+
59
+
60
+ get ( getPath ( `/${ id } ` ) , { method : 'POST' } , ( error , res ) => {
61
+ test . isTrue ( res === "done" ) ;
62
+ } ) ;
44
63
45
- const res2 = HTTP . post ( getPath ( `/${ id } ` ) ) ;
46
- test . isTrue ( res2 . content === "done" ) ;
47
64
} ) ;
48
65
49
66
Tinytest . add ( 'query strings' , function ( test ) {
@@ -52,8 +69,10 @@ Tinytest.add('query strings', function(test) {
52
69
res . end ( "" + params . query . aa ) ;
53
70
} ) ;
54
71
55
- const res = HTTP . get ( getPath ( `/${ id } ?aa=10&bb=10` ) ) ;
56
- test . equal ( res . content , "10" ) ;
72
+ get ( getPath ( `/${ id } ?aa=10&bb=10` ) , { method : 'GET' } , ( error , res ) => {
73
+ test . equal ( res , "10" ) ;
74
+ } ) ;
75
+
57
76
} ) ;
58
77
59
78
Tinytest . add ( 'middlewares' , function ( test ) {
@@ -70,8 +89,10 @@ Tinytest.add('middlewares', function(test) {
70
89
res . end ( req . middlewarePass ) ;
71
90
} ) ;
72
91
73
- const res = HTTP . get ( getPath ( `/${ id } ?aa=10` ) ) ;
74
- test . equal ( res . content , "ok" ) ;
92
+ get ( getPath ( `/${ id } ?aa=10` ) , { method : 'GET' } , ( error , res ) => {
93
+ test . equal ( res , "ok" ) ;
94
+ } ) ;
95
+
75
96
} ) ;
76
97
77
98
Tinytest . add ( 'middlewares - with filtered routes' , function ( test ) {
@@ -93,8 +114,10 @@ Tinytest.add('middlewares - with filtered routes', function(test) {
93
114
res . end ( req . middlewarePass ) ;
94
115
} ) ;
95
116
96
- const res = HTTP . get ( getPath ( path ) ) ;
97
- test . equal ( res . content , "ok" ) ;
117
+ get ( getPath ( path ) , { method : 'GET' } , ( error , res ) => {
118
+ test . equal ( res , "ok" ) ;
119
+ } ) ;
120
+
98
121
} ) ;
99
122
100
123
@@ -125,9 +148,13 @@ Tinytest.add('middlewares - with several filtered routes', function(test) {
125
148
res . end ( req . result + '' ) ;
126
149
} ) ;
127
150
128
- const res1 = HTTP . get ( getPath ( path1 ) ) ;
129
- test . equal ( res1 . content , "11" ) ;
151
+ get ( getPath ( path1 ) , { method : 'GET' } , ( error , res ) => {
152
+ test . equal ( res , "11" ) ;
153
+ } ) ;
154
+
155
+
156
+ get ( getPath ( path2 ) , { method : 'GET' } , ( error , res ) => {
157
+ test . equal ( res , "12" ) ;
158
+ } ) ;
130
159
131
- const res2 = HTTP . get ( getPath ( path2 ) ) ;
132
- test . equal ( res2 . content , "12" ) ;
133
160
} ) ;
0 commit comments