@@ -2,6 +2,8 @@ import 'package:flutter_test/flutter_test.dart';
22import 'package:mocktail/mocktail.dart' ;
33import 'package:http/http.dart' as http;
44
5+ import 'package:emailjs/src/models/emailjs_response_status.dart' ;
6+ import 'package:emailjs/src/types/options.dart' ;
57import 'package:emailjs/emailjs.dart' ;
68
79class MockClient extends Mock implements http.Client {}
@@ -22,7 +24,10 @@ void main() {
2224 });
2325
2426 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+ ));
2631
2732 expect (
2833 () => EmailJS .send ('' , 'my_test_template' ),
@@ -31,7 +36,10 @@ void main() {
3136 });
3237
3338 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+ ));
3543
3644 expect (
3745 () => EmailJS .send ('default_service' , '' ),
@@ -50,14 +58,22 @@ void main() {
5058 body: any (named: 'body' ),
5159 )).thenAnswer ((_) async => http.Response ('OK' , 200 ));
5260
53- EmailJS .init ('LC2JWGTestKeySomething' , null , mockHttpClient);
61+ EmailJS .init (
62+ const Options (
63+ publicKey: 'LC2JWGTestKeySomething' ,
64+ privateKey: 'PrKeyTestKeySomething' ,
65+ ),
66+ null ,
67+ mockHttpClient,
68+ );
5469
5570 try {
5671 final result = await EmailJS .send (
5772 'default_service' ,
5873 'my_test_template' ,
5974 );
60- expect (result, equals ('OK' ));
75+ expect (result.status, 200 );
76+ expect (result.text, 'OK' );
6177 } catch (error) {
6278 expect (error, isNull);
6379 }
@@ -73,16 +89,25 @@ void main() {
7389 )).thenAnswer ((_) async => http.Response ('OK' , 200 ));
7490
7591 // pass the mock http client
76- EmailJS .init ('' , null , mockHttpClient);
92+ EmailJS .init (
93+ const Options (
94+ publicKey: '' ,
95+ ),
96+ null ,
97+ mockHttpClient,
98+ );
7799
78100 try {
79101 final result = await EmailJS .send (
80102 'default_service' ,
81103 'my_test_template' ,
82104 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' );
86111 } catch (error) {
87112 expect (error, isNull);
88113 }
@@ -98,7 +123,14 @@ void main() {
98123 )).thenAnswer ((_) async => http.Response ('The Public Key is required' , 403 ));
99124
100125 // 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+ );
102134
103135 try {
104136 final result = await EmailJS .send (
@@ -107,7 +139,10 @@ void main() {
107139 );
108140 expect (result, isNull);
109141 } 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+ }
111146 }
112147 });
113148 });
0 commit comments