From a5054233c5b5f512df4c4172886c714f82a3849a Mon Sep 17 00:00:00 2001 From: Jonatas Martins Date: Fri, 20 Aug 2021 17:28:27 -0300 Subject: [PATCH] changed variable lastseen to lastseenat --- lib/models/customer.dart | 4 +- lib/utils/getCustomerDetails.dart | 22 +++------ lib/utils/getCustomerDetailsFromMetadata.dart | 2 +- lib/utils/getPastCustomerMessages.dart | 10 ++-- lib/utils/updateUserMetadata.dart | 16 ++----- test/papercups_flutter_test.dart | 47 ++++++------------- test/utils_test.dart | 10 ++-- 7 files changed, 34 insertions(+), 77 deletions(-) diff --git a/lib/models/customer.dart b/lib/models/customer.dart index 1664b69..9943b6e 100644 --- a/lib/models/customer.dart +++ b/lib/models/customer.dart @@ -22,7 +22,7 @@ class PapercupsCustomer { String? id; /// When the customer was last seen. - DateTime? lastSeen; + DateTime? lastSeenAt; /// When the customer details were last updated. DateTime? updatedAt; @@ -33,7 +33,7 @@ class PapercupsCustomer { this.externalId, this.firstSeen, this.id, - this.lastSeen, + this.lastSeenAt, this.updatedAt, this.name, this.phone, diff --git a/lib/utils/getCustomerDetails.dart b/lib/utils/getCustomerDetails.dart index b541128..416d834 100644 --- a/lib/utils/getCustomerDetails.dart +++ b/lib/utils/getCustomerDetails.dart @@ -15,9 +15,7 @@ Future getCustomerDetails( } try { var timeNow = DateTime.now().toUtc().toIso8601String(); - var metadata = p.customer != null && p.customer!.otherMetadata != null - ? p.customer!.otherMetadata! - : {}; + var metadata = p.customer != null && p.customer!.otherMetadata != null ? p.customer!.otherMetadata! : {}; var jsonString = jsonEncode( { "customer": { @@ -26,7 +24,7 @@ Future getCustomerDetails( "email": c != null ? c.email : null, "external_id": c != null ? c.externalId : null, "first_seen": timeNow, - "last_seen": timeNow, + "last_seen_at": timeNow, ...metadata, } }, @@ -40,21 +38,13 @@ Future getCustomerDetails( ); var data = jsonDecode(res.body)["data"]; c = PapercupsCustomer( - createdAt: data["created_at"] != null - ? parseDateFromUTC(data["created_at"]) - : null, + createdAt: data["created_at"] != null ? parseDateFromUTC(data["created_at"]) : null, email: data["email"], externalId: data["external_id"], - firstSeen: data["first_seen"] != null - ? parseDateFromUTC(data["first_seen"]) - : null, + firstSeen: data["first_seen"] != null ? parseDateFromUTC(data["first_seen"]) : null, id: data["id"], - lastSeen: data["last_seen"] != null - ? parseDateFromUTC(data["last_seen"]) - : null, - updatedAt: data["updated_at"] != null - ? parseDateFromUTC(data["updated_at"]) - : null, + lastSeenAt: data["last_seen_at"] != null ? parseDateFromUTC(data["last_seen_at"]) : null, + updatedAt: data["updated_at"] != null ? parseDateFromUTC(data["updated_at"]) : null, name: data["name"], phone: data["phone"], ); diff --git a/lib/utils/getCustomerDetailsFromMetadata.dart b/lib/utils/getCustomerDetailsFromMetadata.dart index 0b3f363..d7bb736 100644 --- a/lib/utils/getCustomerDetailsFromMetadata.dart +++ b/lib/utils/getCustomerDetailsFromMetadata.dart @@ -36,7 +36,7 @@ Future getCustomerDetailsFromMetadata( email: c == null ? null : c.email, createdAt: c == null ? null : c.createdAt, firstSeen: c == null ? null : c.firstSeen, - lastSeen: c == null ? null : c.lastSeen, + lastSeenAt: c == null ? null : c.lastSeenAt, name: c == null ? null : c.name, phone: c == null ? null : c.phone, updatedAt: c == null ? null : c.updatedAt, diff --git a/lib/utils/getPastCustomerMessages.dart b/lib/utils/getPastCustomerMessages.dart index be4b01b..879c45d 100644 --- a/lib/utils/getPastCustomerMessages.dart +++ b/lib/utils/getPastCustomerMessages.dart @@ -47,12 +47,8 @@ Future> getPastCustomerMessages( email: val["user"]["email"], id: val["user"]["id"], role: val["user"]["role"], - fullName: (val["user"]["full_name"] != null) - ? val["user"]["full_name"] - : null, - profilePhotoUrl: (val["user"]["profile_photo_url"] != null) - ? val["user"]["profile_photo_url"] - : null, + fullName: (val["user"]["full_name"] != null) ? val["user"]["full_name"] : null, + profilePhotoUrl: (val["user"]["profile_photo_url"] != null) ? val["user"]["profile_photo_url"] : null, ) : null, ), @@ -66,7 +62,7 @@ Future> getPastCustomerMessages( externalId: customerData["external_id"], firstSeen: parseDateFromUTC(customerData["first_seen"]), id: customerData["id"], - lastSeen: parseDateFromUTC(customerData["last_seen"]), + lastSeenAt: parseDateFromUTC(customerData["last_seen_at"]), updatedAt: parseDateFromUTC(customerData["updated_at"]), name: customerData["name"], phone: customerData["phone"], diff --git a/lib/utils/updateUserMetadata.dart b/lib/utils/updateUserMetadata.dart index 2da1fe2..52e8438 100644 --- a/lib/utils/updateUserMetadata.dart +++ b/lib/utils/updateUserMetadata.dart @@ -29,21 +29,13 @@ Future updateUserMetadata( ); var data = jsonDecode(res.body)["data"]; c = PapercupsCustomer( - createdAt: data["created_at"] != null - ? parseDateFromUTC(data["created_at"]) - : null, + createdAt: data["created_at"] != null ? parseDateFromUTC(data["created_at"]) : null, email: data["email"], externalId: data["external_id"], - firstSeen: data["first_seen"] != null - ? parseDateFromUTC(data["first_seen"]) - : null, + firstSeen: data["first_seen"] != null ? parseDateFromUTC(data["first_seen"]) : null, id: data["id"], - lastSeen: data["last_seen"] != null - ? parseDateFromUTC(data["last_seen"]) - : null, - updatedAt: data["updated_at"] != null - ? parseDateFromUTC(data["updated_at"]) - : null, + lastSeenAt: data["last_seen_at"] != null ? parseDateFromUTC(data["last_seen_at"]) : null, + updatedAt: data["updated_at"] != null ? parseDateFromUTC(data["updated_at"]) : null, name: data["name"], phone: data["phone"], ); diff --git a/test/papercups_flutter_test.dart b/test/papercups_flutter_test.dart index 9163c2a..3e1549b 100644 --- a/test/papercups_flutter_test.dart +++ b/test/papercups_flutter_test.dart @@ -23,7 +23,7 @@ void main() { email: 'email@papercups.com', externalId: 'external_id', firstSeen: parseDateFromUTC('2021-01-08T22:19:52.644532'), - lastSeen: parseDateFromUTC('2021-01-08T22:19:52.644532'), + lastSeenAt: parseDateFromUTC('2021-01-08T22:19:52.644532'), updatedAt: parseDateFromUTC('2021-01-08T22:19:52.644532'), name: 'name', phone: 'phone', @@ -80,8 +80,7 @@ void main() { expect(props.primaryColor, Color(0xffffff)); expect(props.requireEmailUpfront, true); expect(props.scrollEnabled, true); - expect(props.customer!.toJsonString(), - '{"name":null,"email":null,"external_id":null}'); + expect(props.customer!.toJsonString(), '{"name":null,"email":null,"external_id":null}'); expect(props.primaryGradient, null); expect(props.subtitle, "How can we help you?"); expect(props.title, "Welcome!"); @@ -98,24 +97,18 @@ void main() { expect(cm.externalId, null); expect(cm.name, null); expect(cm.otherMetadata, null); - expect( - cm.toJsonString(), '{"name":null,"email":null,"external_id":null}'); + expect(cm.toJsonString(), '{"name":null,"email":null,"external_id":null}'); }); test('are loaded correctly', () { - cm = CustomerMetadata( - email: "test@test.com", - externalId: "1234", - name: "name", - otherMetadata: { - "Test": "string", - }); + cm = CustomerMetadata(email: "test@test.com", externalId: "1234", name: "name", otherMetadata: { + "Test": "string", + }); expect(cm.email, "test@test.com"); expect(cm.externalId, "1234"); expect(cm.name, "name"); expect(cm.otherMetadata, {"Test": "string"}); - expect(cm.toJsonString(), - '{"name":"name","email":"test@test.com","external_id":"1234","Test":"string"}'); + expect(cm.toJsonString(), '{"name":"name","email":"test@test.com","external_id":"1234","Test":"string"}'); }); }); group('Theming', () { @@ -218,8 +211,7 @@ void main() { ).thenAnswer((_) => throw (HttpException('Request failed'))); expect( - getConversationDetails(props, Conversation(), customer, () => {}, - client: client), + getConversationDetails(props, Conversation(), customer, () => {}, client: client), throwsException, ); }); @@ -236,7 +228,7 @@ void main() { "external_id": customer.externalId, "created_at": customer.createdAt!.toUtc().toIso8601String(), "first_seen": customer.firstSeen!.toUtc().toIso8601String(), - "last_seen": customer.lastSeen!.toUtc().toIso8601String(), + "last_seen_at": customer.lastSeenAt!.toUtc().toIso8601String(), "updated_at": customer.updatedAt!.toUtc().toIso8601String(), "name": customer.name, "phone": customer.phone, @@ -269,7 +261,7 @@ void main() { verify(client.close()).called(1); expect(c.id, equals(customer.id)); - expect(c.lastSeen, equals(customer.lastSeen)); + expect(c.lastSeenAt, equals(customer.lastSeenAt)); }); test("throws an exception when there's an error", () async { @@ -301,7 +293,7 @@ void main() { "external_id": customer.externalId, "created_at": customer.createdAt!.toIso8601String(), "first_seen": customer.firstSeen!.toIso8601String(), - "last_seen": customer.lastSeen!.toIso8601String(), + "last_seen_at": customer.lastSeenAt!.toIso8601String(), "updated_at": customer.updatedAt!.toIso8601String(), "name": customer.name, "phone": customer.phone, @@ -345,7 +337,7 @@ void main() { verify(client.close()).called(1); expect(c.id, equals(customer.id)); - expect(c.lastSeen, equals(customer.lastSeen)); + expect(c.lastSeenAt, equals(customer.lastSeenAt)); }); test("throws an exception when there's an error", () async { @@ -365,9 +357,7 @@ void main() { ), ).thenThrow(HttpException('Request failed')); - expect( - getCustomerDetailsFromMetadata(props, customer, sc, client: client), - throwsException); + expect(getCustomerDetailsFromMetadata(props, customer, sc, client: client), throwsException); }); }); @@ -393,16 +383,7 @@ void main() { "sent_at": message.sentAt!.toIso8601String(), } ], - "customer": { - "created_at": customer.createdAt!.toIso8601String(), - "email": customer.email, - "external_id": customer.externalId, - "first_seen": customer.firstSeen!.toIso8601String(), - "last_seen": customer.lastSeen!.toIso8601String(), - "updated_at": customer.updatedAt!.toIso8601String(), - "name": customer.name, - "phone": customer.phone - } + "customer": {"created_at": customer.createdAt!.toIso8601String(), "email": customer.email, "external_id": customer.externalId, "first_seen": customer.firstSeen!.toIso8601String(), "last_seen_at": customer.lastSeenAt!.toIso8601String(), "updated_at": customer.updatedAt!.toIso8601String(), "name": customer.name, "phone": customer.phone} } ] }); diff --git a/test/utils_test.dart b/test/utils_test.dart index b8d6258..8870d10 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -17,7 +17,7 @@ void main() { email: 'email@papercups.com', externalId: 'external_id', firstSeen: DateTime.tryParse('2021-01-08T22:19:52.644532'), - lastSeen: DateTime.tryParse('2021-01-08T22:19:52.644532'), + lastSeenAt: DateTime.tryParse('2021-01-08T22:19:52.644532'), updatedAt: DateTime.tryParse('2021-01-08T22:19:52.644532'), name: 'name', phone: 'phone', @@ -37,7 +37,7 @@ void main() { "external_id": customer.externalId, "created_at": customer.createdAt!.toUtc().toIso8601String(), "first_seen": customer.firstSeen!.toUtc().toIso8601String(), - "last_seen": customer.lastSeen!.toUtc().toIso8601String(), + "last_seen_at": customer.lastSeenAt!.toUtc().toIso8601String(), "updated_at": customer.updatedAt!.toUtc().toIso8601String(), "name": customer.name, "phone": customer.phone, @@ -53,8 +53,7 @@ void main() { ).thenAnswer((_) async => http.Response(res, 200)); when(client.close()).thenReturn(null); - final PapercupsCustomer? c = - await (updateUserMetadata(props, customer.id, client: client)); + final PapercupsCustomer? c = await (updateUserMetadata(props, customer.id, client: client)); verify( client.put( @@ -80,8 +79,7 @@ void main() { ).thenThrow(HttpException('Request failed')); when(client.close()).thenReturn(null); - final PapercupsCustomer? c = - await updateUserMetadata(props, customer.id, client: client); + final PapercupsCustomer? c = await updateUserMetadata(props, customer.id, client: client); verify( client.put(