Skip to content

Commit

Permalink
changed variable lastseen to lastseenat
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonatas Martins authored and aguilaair committed Aug 21, 2021
1 parent a45c068 commit a505423
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 77 deletions.
4 changes: 2 additions & 2 deletions lib/models/customer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +33,7 @@ class PapercupsCustomer {
this.externalId,
this.firstSeen,
this.id,
this.lastSeen,
this.lastSeenAt,
this.updatedAt,
this.name,
this.phone,
Expand Down
22 changes: 6 additions & 16 deletions lib/utils/getCustomerDetails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ Future<PapercupsCustomer> 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": {
Expand All @@ -26,7 +24,7 @@ Future<PapercupsCustomer> 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,
}
},
Expand All @@ -40,21 +38,13 @@ Future<PapercupsCustomer> 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"],
);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/getCustomerDetailsFromMetadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Future<PapercupsCustomer> 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,
Expand Down
10 changes: 3 additions & 7 deletions lib/utils/getPastCustomerMessages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ Future<Map<String, dynamic>> 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,
),
Expand All @@ -66,7 +62,7 @@ Future<Map<String, dynamic>> 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"],
Expand Down
16 changes: 4 additions & 12 deletions lib/utils/updateUserMetadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@ Future<PapercupsCustomer?> 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"],
);
Expand Down
47 changes: 14 additions & 33 deletions test/papercups_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
email: '[email protected]',
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',
Expand Down Expand Up @@ -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!");
Expand All @@ -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: "[email protected]",
externalId: "1234",
name: "name",
otherMetadata: {
"Test": "string",
});
cm = CustomerMetadata(email: "[email protected]", externalId: "1234", name: "name", otherMetadata: {
"Test": "string",
});

expect(cm.email, "[email protected]");
expect(cm.externalId, "1234");
expect(cm.name, "name");
expect(cm.otherMetadata, {"Test": "string"});
expect(cm.toJsonString(),
'{"name":"name","email":"[email protected]","external_id":"1234","Test":"string"}');
expect(cm.toJsonString(), '{"name":"name","email":"[email protected]","external_id":"1234","Test":"string"}');
});
});
group('Theming', () {
Expand Down Expand Up @@ -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,
);
});
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
});
});

Expand All @@ -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}
}
]
});
Expand Down
10 changes: 4 additions & 6 deletions test/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
email: '[email protected]',
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',
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit a505423

Please sign in to comment.