1+ import 'package:integration_test/integration_test.dart' ;
12import 'package:courier_flutter/courier_preference_channel.dart' ;
23import 'package:courier_flutter/courier_preference_status.dart' ;
34import 'package:courier_flutter/models/courier_device.dart' ;
45import 'package:courier_flutter/models/courier_tracking_event.dart' ;
56import 'package:courier_flutter_sample/env.dart' ;
67import 'package:flutter_test/flutter_test.dart' ;
7- import 'package:integration_test/integration_test.dart' ;
88import 'package:uuid/uuid.dart' ;
99
10- import 'client_builder.dart' ;
11- import 'example_server.dart' ;
10+ import 'utils.dart' ;
1211
1312void main () {
13+
1414 IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
1515
16- final userId = const Uuid ().v1 ();
16+ final userId = const Uuid ().v4 ();
1717 const trackingUrl = "https://af6303be-0e1e-40b5-bb80-e1d9299cccff.ct0.app/t/tzgspbr4jcmcy1qkhw96m0034bvy" ;
1818
19- Future <String > sendMessage (String userId) {
20- return ExampleServer .sendTest (Env .authKey, userId, "inbox" );
21- }
19+ group ('Options' , () {
2220
23- Future delay ({int milliseconds = 5000 }) {
24- return Future .delayed (Duration (milliseconds: milliseconds));
25- }
26-
27- group ('Client Tests' , () {
28- test ('Options are setup' , () async {
21+ test ('Setup' , () async {
2922 final client = await ClientBuilder .build (userId: userId);
3023 final options = client.options;
3124 expect (options.userId, userId);
3225 });
26+
3327 });
3428
3529 group ('Brand Tests' , () {
30+
3631 test ('Get Brand' , () async {
3732 final client = await ClientBuilder .build (userId: userId);
3833 final res = await client.brands.getBrand (brandId: Env .brandId);
3934 expect (res.data? .brand, isNotNull);
4035 expect (res.data? .brand? .settings? .inapp? .showCourierFooter, false );
4136 });
37+
4238 });
4339
4440 group ('Token Management Tests' , () {
41+
4542 test ('Put Token' , () async {
4643 final client = await ClientBuilder .build (userId: userId);
4744 await client.tokens.putUserToken (
4845 token: 'example_token' ,
4946 provider: 'firebase-fcm' ,
5047 );
5148 });
49+
5250 test ('Put Token with Device' , () async {
5351 final client = await ClientBuilder .build (userId: userId);
5452 final device = CourierDevice (appId: 'example_app_id' );
@@ -58,6 +56,7 @@ void main() {
5856 device: device,
5957 );
6058 });
59+
6160 test ('Delete Token' , () async {
6261 final client = await ClientBuilder .build (userId: userId);
6362 final device = CourierDevice (appId: 'example_app_id' );
@@ -70,33 +69,39 @@ void main() {
7069 });
7170
7271 group ('Tracking Tests' , () {
72+
7373 test ('Track Delivered' , () async {
7474 final client = await ClientBuilder .build (userId: userId);
7575 await client.tracking.postTrackingUrl (
7676 url: trackingUrl,
7777 event: CourierTrackingEvent .delivered,
7878 );
7979 });
80+
8081 test ('Track Clicked' , () async {
8182 final client = await ClientBuilder .build (userId: userId);
8283 await client.tracking.postTrackingUrl (
8384 url: trackingUrl,
8485 event: CourierTrackingEvent .clicked,
8586 );
8687 });
88+
8789 });
8890
8991 group ('Preferences Tests' , () {
92+
9093 test ('Get Preferences' , () async {
9194 final client = await ClientBuilder .build (userId: userId);
9295 final res = await client.preferences.getUserPreferences ();
9396 expect (res.items, isNotEmpty);
9497 });
98+
9599 test ('Get Preference Topic' , () async {
96100 final client = await ClientBuilder .build (userId: userId);
97101 final res = await client.preferences.getUserPreferenceTopic (topicId: Env .preferenceTopicId);
98102 expect (res.topic.topicId, Env .preferenceTopicId);
99103 });
104+
100105 test ('Put Preference Topic' , () async {
101106 final client = await ClientBuilder .build (userId: userId);
102107 await client.preferences.putUserPreferenceTopic (
@@ -106,26 +111,37 @@ void main() {
106111 customRouting: [CourierUserPreferencesChannel .push],
107112 );
108113 });
114+
109115 });
110116
111117 group ('Inbox Tests' , () {
118+
112119 test ('Get All Messages' , () async {
120+ await sendMessage (userId);
121+ await delay ();
113122 final client = await ClientBuilder .build (userId: userId);
114123 final res = await client.inbox.getMessages ();
115- expect (res.data? .messages, isNotNull );
124+ expect (res.data? .messages? .nodes ? .length, 1 );
116125 });
126+
117127 test ('Get Archived Messages' , () async {
128+ final messageId = await sendMessage (userId);
129+ await delay ();
118130 final client = await ClientBuilder .build (userId: userId);
131+ await client.inbox.archive (messageId: messageId);
119132 final res = await client.inbox.getArchivedMessages ();
120- expect (res.data? .messages, isNotNull);
133+ final message = res.data? .messages? .nodes? .first;
134+ expect (message? .archived, true );
121135 });
136+
122137 test ('Get Message By ID' , () async {
123138 final messageId = await sendMessage (userId);
124139 await delay ();
125140 final client = await ClientBuilder .build (userId: userId);
126141 final res = await client.inbox.getMessageById (messageId: messageId);
127142 expect (res.data? .message.messageId, messageId);
128143 });
144+
129145 test ('Get Unread Message Count' , () async {
130146 final newUser = const Uuid ().v1 ();
131147 await sendMessage (newUser);
@@ -134,41 +150,49 @@ void main() {
134150 final count = await client.inbox.getUnreadMessageCount ();
135151 expect (count, 1 );
136152 });
153+
137154 test ('Open Message' , () async {
138155 final messageId = await sendMessage (userId);
139156 await delay ();
140157 final client = await ClientBuilder .build (userId: userId);
141158 await client.inbox.open (messageId: messageId);
142159 });
160+
143161 test ('Click Message' , () async {
144162 final messageId = await sendMessage (userId);
145163 await delay ();
146164 final client = await ClientBuilder .build (userId: userId);
147165 await client.inbox.click (messageId: messageId, trackingId: "example_id" );
148166 });
167+
149168 test ('Read Message' , () async {
150169 final messageId = await sendMessage (userId);
151170 await delay ();
152171 final client = await ClientBuilder .build (userId: userId);
153172 await client.inbox.read (messageId: messageId);
154173 });
174+
155175 test ('Unread Message' , () async {
156176 final messageId = await sendMessage (userId);
157177 await delay ();
158178 final client = await ClientBuilder .build (userId: userId);
159179 await client.inbox.unread (messageId: messageId);
160180 });
181+
161182 test ('Archive Message' , () async {
162183 final messageId = await sendMessage (userId);
163184 await delay ();
164185 final client = await ClientBuilder .build (userId: userId);
165186 await client.inbox.archive (messageId: messageId);
166187 });
188+
167189 test ('Read All Messages' , () async {
168190 await sendMessage (userId);
169191 await delay ();
170192 final client = await ClientBuilder .build (userId: userId);
171193 await client.inbox.readAll ();
172194 });
195+
173196 });
197+
174198}
0 commit comments