|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
| 4 | +using System.Globalization; |
4 | 5 | using System.Linq;
|
5 | 6 | using LootLocker;
|
6 | 7 | using LootLocker.LootLockerEnums;
|
@@ -36,7 +37,7 @@ public IEnumerator Setup()
|
36 | 37 | }
|
37 | 38 |
|
38 | 39 | bool gameCreationCallCompleted = false;
|
39 |
| - LootLockerTestGame.CreateGame(testName: "NotificationTest" + TestCounter + " ", onComplete: (success, errorMessage, game) => |
| 40 | + LootLockerTestGame.CreateGame(testName: "NotificationTest" + TestCounter, onComplete: (success, errorMessage, game) => |
40 | 41 | {
|
41 | 42 | if (!success)
|
42 | 43 | {
|
@@ -552,5 +553,204 @@ public IEnumerator Notifications_MarkAllNotificationsAsReadUsingConvenienceMetho
|
552 | 553 | Assert.IsTrue(listUnreadNotificationsAfterMarkAsReadResponse.success, "Listing unread notifications after marking specific as read failed");
|
553 | 554 | Assert.AreEqual(CreatedTriggers.Count - notificationIdsToMarkAsRead.Length, listUnreadNotificationsAfterMarkAsReadResponse.Notifications.Length, "Not all notifications that were marked as read actually were");
|
554 | 555 | }
|
555 |
| - } |
| 556 | + |
| 557 | + [UnityTest] |
| 558 | + public IEnumerator Notifications_ConvenienceLookupTable_CanLookUpAllNotificationTypes() |
| 559 | + { |
| 560 | + Assert.IsFalse(SetupFailed, "Setup did not succeed"); |
| 561 | + |
| 562 | + // Given |
| 563 | + string TriggerIdentifyingValue = "trigger_key"; |
| 564 | + string triggerNotification1Id = GUID.Generate().ToString(); |
| 565 | + string triggerNotification2Id = GUID.Generate().ToString(); |
| 566 | + string triggerNotification3Id = GUID.Generate().ToString(); |
| 567 | + string LootLockerVirtualStorePurchaseIdentifyingValue = "catalog_item_id"; |
| 568 | + string lootLockerVirtualStoreNotification1Id = GUID.Generate().ToString(); |
| 569 | + string AppleAppStorePurchaseIdentifyingValue = "transaction_id"; |
| 570 | + string appleAppStoreNotification1Id = GUID.Generate().ToString(); |
| 571 | + string GooglePlayStoreStorePurchaseIdentifyingValue = "product_id"; |
| 572 | + string googlePlayStoreNotification1Id = GUID.Generate().ToString(); |
| 573 | + var fakeResponse = new LootLockerListNotificationsResponse() |
| 574 | + { |
| 575 | + statusCode = 200, |
| 576 | + success = true, |
| 577 | + text = "", |
| 578 | + errorData = null, |
| 579 | + EventId = "1234", |
| 580 | + Pagination = new LootLockerExtendedPagination |
| 581 | + { |
| 582 | + errors = null, |
| 583 | + current_page = 1, |
| 584 | + prev_page = null, |
| 585 | + next_page = null, |
| 586 | + last_page = 1, |
| 587 | + offset = 0, |
| 588 | + per_page = 100, |
| 589 | + total = 6 |
| 590 | + }, |
| 591 | + Notifications = new LootLockerNotification[] |
| 592 | + { |
| 593 | + GenerateLootLockerNotification(triggerNotification1Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Triggers, TriggerIdentifyingValue), |
| 594 | + GenerateLootLockerNotification(triggerNotification2Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Triggers, TriggerIdentifyingValue), |
| 595 | + GenerateLootLockerNotification(triggerNotification3Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Triggers, "some_other_trigger"), |
| 596 | + GenerateLootLockerNotification(lootLockerVirtualStoreNotification1Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.LootLocker, LootLockerVirtualStorePurchaseIdentifyingValue), |
| 597 | + GenerateLootLockerNotification(appleAppStoreNotification1Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.AppleAppStore, AppleAppStorePurchaseIdentifyingValue), |
| 598 | + GenerateLootLockerNotification(googlePlayStoreNotification1Id, LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.GooglePlayStore, GooglePlayStoreStorePurchaseIdentifyingValue), |
| 599 | + } |
| 600 | + }; |
| 601 | + |
| 602 | + fakeResponse.PopulateConvenienceStructures(); |
| 603 | + |
| 604 | + // When |
| 605 | + bool triggerLookupSucceeded = fakeResponse.TryGetNotificationsByIdentifyingValue(TriggerIdentifyingValue, out var triggerNotifications); |
| 606 | + bool lootLockerVirtualStoreLookupSucceeded = fakeResponse.TryGetNotificationsByIdentifyingValue(LootLockerVirtualStorePurchaseIdentifyingValue, out var lootLockerVirtualStoreNotifications); |
| 607 | + bool appleAppStoreLookupSucceeded = fakeResponse.TryGetNotificationsByIdentifyingValue(AppleAppStorePurchaseIdentifyingValue, out var appleAppStoreNotifications); |
| 608 | + bool googlePlayStoreLookupSucceeded = fakeResponse.TryGetNotificationsByIdentifyingValue(GooglePlayStoreStorePurchaseIdentifyingValue, out var googlePlayStoreNotifications); |
| 609 | + |
| 610 | + // Then |
| 611 | + Assert.IsTrue(triggerLookupSucceeded, "Trigger notification lookup failed"); |
| 612 | + Assert.IsNotEmpty(triggerNotifications, "Trigger notification lookup array was empty"); |
| 613 | + Assert.AreEqual(2, triggerNotifications.Length, "The right amount of trigger notifications were not retrieved"); |
| 614 | + var retrievedNotificationIds = triggerNotifications.Take(2).Select(notification => notification.Id).ToArray(); |
| 615 | + Assert.Contains(triggerNotification1Id, retrievedNotificationIds, "The retrieved trigger notifications did not contain the expected id"); |
| 616 | + Assert.Contains(triggerNotification2Id, retrievedNotificationIds, "The retrieved trigger notifications did not contain the expected id"); |
| 617 | + |
| 618 | + Assert.IsTrue(lootLockerVirtualStoreLookupSucceeded, "LootLocker Virtual Store notification lookup failed"); |
| 619 | + Assert.IsNotEmpty(lootLockerVirtualStoreNotifications, "LootLocker Virtual Store notification lookup array was empty"); |
| 620 | + Assert.AreEqual(lootLockerVirtualStoreNotification1Id, lootLockerVirtualStoreNotifications[0].Id, "The retrieved lootlocker virtual store notification id was not as expected"); |
| 621 | + |
| 622 | + Assert.IsTrue(appleAppStoreLookupSucceeded, "Apple app store notification lookup failed"); |
| 623 | + Assert.IsNotEmpty(appleAppStoreNotifications, "Apple app store notification lookup array was empty"); |
| 624 | + Assert.AreEqual(appleAppStoreNotification1Id, appleAppStoreNotifications[0].Id, "The retrieved Apple app store notification id was not as expected"); |
| 625 | + |
| 626 | + Assert.IsTrue(googlePlayStoreLookupSucceeded, "Google Play store notification lookup failed"); |
| 627 | + Assert.IsNotEmpty(googlePlayStoreNotifications, "Google Play store notification lookup array was empty"); |
| 628 | + Assert.AreEqual(googlePlayStoreNotification1Id, googlePlayStoreNotifications[0].Id, "The retrieved Google Play store notification id was not as expected"); |
| 629 | + |
| 630 | + yield break; |
| 631 | + } |
| 632 | + |
| 633 | + private static LootLockerNotification GenerateLootLockerNotification(string notificationId, string source, string identifyingValue) |
| 634 | + { |
| 635 | + LootLockerNotificationContextEntry[] context = null; |
| 636 | + if (source.Equals(LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Triggers, StringComparison.OrdinalIgnoreCase)) |
| 637 | + { |
| 638 | + context = new[] |
| 639 | + { |
| 640 | + new LootLockerNotificationContextEntry |
| 641 | + { |
| 642 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Triggers.Key, |
| 643 | + Value = identifyingValue |
| 644 | + }, |
| 645 | + new LootLockerNotificationContextEntry |
| 646 | + { |
| 647 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Triggers.Id, |
| 648 | + Value = GUID.Generate().ToString(), |
| 649 | + }, |
| 650 | + new LootLockerNotificationContextEntry |
| 651 | + { |
| 652 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Triggers.Limit, |
| 653 | + Value = "10" |
| 654 | + } |
| 655 | + }; |
| 656 | + } |
| 657 | + else if (source.Equals(LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.LootLocker, StringComparison.OrdinalIgnoreCase)) |
| 658 | + { |
| 659 | + context = new[] |
| 660 | + { |
| 661 | + new LootLockerNotificationContextEntry |
| 662 | + { |
| 663 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.LootLocker.CatalogItemId, |
| 664 | + Value = identifyingValue |
| 665 | + }, |
| 666 | + new LootLockerNotificationContextEntry |
| 667 | + { |
| 668 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.LootLocker.CatalogId, |
| 669 | + Value = GUID.Generate().ToString(), |
| 670 | + } |
| 671 | + }; |
| 672 | + } |
| 673 | + else if (source.Equals(LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.GooglePlayStore, StringComparison.OrdinalIgnoreCase)) |
| 674 | + { |
| 675 | + context = new[] |
| 676 | + { |
| 677 | + new LootLockerNotificationContextEntry |
| 678 | + { |
| 679 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.GooglePlayStore.ProductId, |
| 680 | + Value = identifyingValue |
| 681 | + }, |
| 682 | + new LootLockerNotificationContextEntry |
| 683 | + { |
| 684 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.GooglePlayStore.CatalogItemId, |
| 685 | + Value = GUID.Generate().ToString(), |
| 686 | + }, |
| 687 | + new LootLockerNotificationContextEntry |
| 688 | + { |
| 689 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.GooglePlayStore.CatalogId, |
| 690 | + Value = GUID.Generate().ToString() |
| 691 | + } |
| 692 | + }; |
| 693 | + } |
| 694 | + else if (source.Equals(LootLocker.LootLockerStaticStrings.LootLockerNotificationSources.Purchasing.AppleAppStore, StringComparison.OrdinalIgnoreCase)) |
| 695 | + { |
| 696 | + context = new[] |
| 697 | + { |
| 698 | + new LootLockerNotificationContextEntry |
| 699 | + { |
| 700 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.AppleAppStore.TransactionId, |
| 701 | + Value = identifyingValue |
| 702 | + }, |
| 703 | + new LootLockerNotificationContextEntry |
| 704 | + { |
| 705 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.AppleAppStore.CatalogItemId, |
| 706 | + Value = GUID.Generate().ToString(), |
| 707 | + }, |
| 708 | + new LootLockerNotificationContextEntry |
| 709 | + { |
| 710 | + Key = LootLocker.LootLockerStaticStrings.LootLockerStandardContextKeys.Purchasing.AppleAppStore.CatalogId, |
| 711 | + Value = GUID.Generate().ToString() |
| 712 | + } |
| 713 | + }; |
| 714 | + } |
| 715 | + return new LootLockerNotification |
| 716 | + { |
| 717 | + Id = notificationId, |
| 718 | + Created_at = DateTime.Now, |
| 719 | + Expiration_date = DateTime.Now.AddDays(30).ToString(CultureInfo.InvariantCulture), |
| 720 | + Player_id = GUID.Generate().ToString(), |
| 721 | + Priority = LootLockerNotificationPriority.medium, |
| 722 | + Read = false, |
| 723 | + Read_at = null, |
| 724 | + Notification_type = LootLocker.LootLockerStaticStrings.LootLockerNotificationTypes.PullRewardAcquired, |
| 725 | + Source = source, |
| 726 | + Content = new LootLockerNotificationContent |
| 727 | + { |
| 728 | + Context = context, |
| 729 | + Body = new LootLockerNotificationContentBody |
| 730 | + { |
| 731 | + Kind = LootLockerNotificationContentKind.currency, |
| 732 | + Asset = null, |
| 733 | + Group = null, |
| 734 | + Progression_reset = null, |
| 735 | + Progression_points = null, |
| 736 | + Currency = new LootLockerNotificationRewardCurrency |
| 737 | + { |
| 738 | + Amount = "100", |
| 739 | + Created_at = DateTime.Now, |
| 740 | + Currency_id = GUID.Generate().ToString(), |
| 741 | + Reward_id = GUID.Generate().ToString(), |
| 742 | + Updated_at = DateTime.Now, |
| 743 | + Details = new LootLockerNotificationRewardCurrencyDetails |
| 744 | + { |
| 745 | + Amount = "100", |
| 746 | + Code = "GLD", |
| 747 | + Id = GUID.Generate().ToString(), |
| 748 | + Name = "Gold" |
| 749 | + } |
| 750 | + } |
| 751 | + } |
| 752 | + } |
| 753 | + }; |
| 754 | + } |
| 755 | +} |
556 | 756 | }
|
0 commit comments