@@ -2,6 +2,8 @@ import 'package:flutter_test/flutter_test.dart';
2
2
import 'package:mocktail/mocktail.dart' ;
3
3
import 'package:http/http.dart' as http;
4
4
5
+ import 'package:emailjs/src/models/emailjs_response_status.dart' ;
6
+ import 'package:emailjs/src/types/options.dart' ;
5
7
import 'package:emailjs/emailjs.dart' ;
6
8
7
9
class MockClient extends Mock implements http.Client {}
@@ -22,7 +24,10 @@ void main() {
22
24
});
23
25
24
26
test ('should send method and fail on the service ID' , () {
25
- EmailJS .init ('LC2JWGTestKeySomething' );
27
+ EmailJS .init (const Options (
28
+ publicKey: 'LC2JWGTestKeySomething' ,
29
+ privateKey: 'PrKeyTestKeySomething' ,
30
+ ));
26
31
27
32
expect (
28
33
() => EmailJS .send ('' , 'my_test_template' ),
@@ -31,7 +36,10 @@ void main() {
31
36
});
32
37
33
38
test ('should send method and fail on the template ID' , () {
34
- EmailJS .init ('LC2JWGTestKeySomething' );
39
+ EmailJS .init (const Options (
40
+ publicKey: 'LC2JWGTestKeySomething' ,
41
+ privateKey: 'PrKeyTestKeySomething' ,
42
+ ));
35
43
36
44
expect (
37
45
() => EmailJS .send ('default_service' , '' ),
@@ -50,14 +58,22 @@ void main() {
50
58
body: any (named: 'body' ),
51
59
)).thenAnswer ((_) async => http.Response ('OK' , 200 ));
52
60
53
- EmailJS .init ('LC2JWGTestKeySomething' , null , mockHttpClient);
61
+ EmailJS .init (
62
+ const Options (
63
+ publicKey: 'LC2JWGTestKeySomething' ,
64
+ privateKey: 'PrKeyTestKeySomething' ,
65
+ ),
66
+ null ,
67
+ mockHttpClient,
68
+ );
54
69
55
70
try {
56
71
final result = await EmailJS .send (
57
72
'default_service' ,
58
73
'my_test_template' ,
59
74
);
60
- expect (result, equals ('OK' ));
75
+ expect (result.status, 200 );
76
+ expect (result.text, 'OK' );
61
77
} catch (error) {
62
78
expect (error, isNull);
63
79
}
@@ -73,16 +89,25 @@ void main() {
73
89
)).thenAnswer ((_) async => http.Response ('OK' , 200 ));
74
90
75
91
// pass the mock http client
76
- EmailJS .init ('' , null , mockHttpClient);
92
+ EmailJS .init (
93
+ const Options (
94
+ publicKey: '' ,
95
+ ),
96
+ null ,
97
+ mockHttpClient,
98
+ );
77
99
78
100
try {
79
101
final result = await EmailJS .send (
80
102
'default_service' ,
81
103
'my_test_template' ,
82
104
null ,
83
- 'LC2JWGTestKeySomething' ,
84
- );
85
- expect (result, equals ('OK' ));
105
+ const Options (
106
+ publicKey: 'LC2JWGTestKeySomething' ,
107
+ privateKey: 'PrKeyTestKeySomething' ,
108
+ ));
109
+ expect (result.status, 200 );
110
+ expect (result.text, 'OK' );
86
111
} catch (error) {
87
112
expect (error, isNull);
88
113
}
@@ -98,7 +123,14 @@ void main() {
98
123
)).thenAnswer ((_) async => http.Response ('The Public Key is required' , 403 ));
99
124
100
125
// pass the mock http client
101
- EmailJS .init ('LC2JWGTestKeySomething' , null , mockHttpClient);
126
+ EmailJS .init (
127
+ const Options (
128
+ publicKey: 'LC2JWGTestKeySomething' ,
129
+ privateKey: 'PrKeyTestKeySomething' ,
130
+ ),
131
+ null ,
132
+ mockHttpClient,
133
+ );
102
134
103
135
try {
104
136
final result = await EmailJS .send (
@@ -107,7 +139,10 @@ void main() {
107
139
);
108
140
expect (result, isNull);
109
141
} catch (error) {
110
- expect (error, equals ('The Public Key is required' ));
142
+ if (error is EmailJSResponseStatus ) {
143
+ expect (error.status, 403 );
144
+ expect (error.text, 'The Public Key is required' );
145
+ }
111
146
}
112
147
});
113
148
});
0 commit comments