(t *testing.T)
| 895 | } |
| 896 | |
| 897 | func TestRealtimeCustomAuthModelDeleteEvent(t *testing.T) { |
| 898 | testApp, _ := tests.NewTestApp() |
| 899 | defer testApp.Cleanup() |
| 900 | |
| 901 | // init realtime handlers |
| 902 | _, err := apis.NewRouter(testApp) |
| 903 | if err != nil { |
| 904 | t.Fatal(err) |
| 905 | } |
| 906 | |
| 907 | authRecord1, err := testApp.FindAuthRecordByEmail("users", "test@example.com") |
| 908 | if err != nil { |
| 909 | t.Fatal(err) |
| 910 | } |
| 911 | |
| 912 | authRecord2, err := testApp.FindAuthRecordByEmail("users", "test2@example.com") |
| 913 | if err != nil { |
| 914 | t.Fatal(err) |
| 915 | } |
| 916 | |
| 917 | client1 := subscriptions.NewDefaultClient() |
| 918 | client1.Set(apis.RealtimeClientAuthKey, authRecord1) |
| 919 | testApp.SubscriptionsBroker().Register(client1) |
| 920 | |
| 921 | client2 := subscriptions.NewDefaultClient() |
| 922 | client2.Set(apis.RealtimeClientAuthKey, authRecord1) |
| 923 | testApp.SubscriptionsBroker().Register(client2) |
| 924 | |
| 925 | client3 := subscriptions.NewDefaultClient() |
| 926 | client3.Set(apis.RealtimeClientAuthKey, authRecord2) |
| 927 | testApp.SubscriptionsBroker().Register(client3) |
| 928 | |
| 929 | // refetch the authRecord as CustomUser |
| 930 | customUser, err := findCustomUserByEmail(testApp, authRecord1.Email()) |
| 931 | if err != nil { |
| 932 | t.Fatal(err) |
| 933 | } |
| 934 | |
| 935 | // delete the custom user (should unset the client auth record) |
| 936 | if err := testApp.Delete(customUser); err != nil { |
| 937 | t.Fatal(err) |
| 938 | } |
| 939 | |
| 940 | if total := len(testApp.SubscriptionsBroker().Clients()); total != 3 { |
| 941 | t.Fatalf("Expected %d subscription clients, found %d", 3, total) |
| 942 | } |
| 943 | |
| 944 | if auth := client1.Get(apis.RealtimeClientAuthKey); auth != nil { |
| 945 | t.Fatalf("[client1] Expected the auth state to be unset, found %#v", auth) |
| 946 | } |
| 947 | |
| 948 | if auth := client2.Get(apis.RealtimeClientAuthKey); auth != nil { |
| 949 | t.Fatalf("[client2] Expected the auth state to be unset, found %#v", auth) |
| 950 | } |
| 951 | |
| 952 | if auth := client3.Get(apis.RealtimeClientAuthKey); auth == nil || auth.(*core.Record).Id != authRecord2.Id { |
| 953 | t.Fatalf("[client3] Expected the auth state to be left unchanged, found %#v", auth) |
| 954 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…