github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/home/home_test.go (about) 1 package home 2 3 import ( 4 "context" 5 "github.com/keybase/client/go/contacts" 6 "testing" 7 8 "github.com/keybase/client/go/kbtest" 9 "github.com/keybase/client/go/libkb" 10 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/stretchr/testify/require" 12 ) 13 14 // General coverage over public methods and covers an issue where we previously 15 // referenced a null cache. 16 func TestHome(t *testing.T) { 17 tc := libkb.SetupTest(t, "home", 2) 18 defer tc.Cleanup() 19 _, err := kbtest.CreateAndSignupFakeUser("t", tc.G) 20 require.NoError(t, err) 21 22 ctx := context.TODO() 23 home := NewHome(tc.G) 24 25 // test we run without error for markViewed true/false 26 numPeopleWanted := 0 // makes mock cache easier 27 for _, markViewed := range []bool{true, false} { 28 _, err = home.Get(ctx, markViewed, numPeopleWanted) 29 require.NoError(t, err) 30 31 // setup caches so we test those branches 32 newPeopleCache := &peopleCache{ 33 all: []keybase1.HomeUserSummary{ 34 {}, 35 }, 36 cachedAt: tc.G.GetClock().Now(), 37 } 38 home.peopleCache = newPeopleCache 39 home.homeCache = &homeCache{ 40 cachedAt: tc.G.GetClock().Now(), 41 obj: keybase1.HomeScreen{ 42 Items: []keybase1.HomeScreenItem{ 43 { 44 Badged: true, 45 Data: keybase1.NewHomeScreenItemDataWithPeople(keybase1.HomeScreenPeopleNotification{}), 46 }, 47 }, 48 }, 49 } 50 useCache, _ := home.peopleCache.isValid(ctx, tc.G, numPeopleWanted) 51 require.True(t, useCache) 52 require.True(t, home.homeCache.isValid(ctx, tc.G)) 53 _, err = home.Get(ctx, markViewed, numPeopleWanted) 54 require.NoError(t, err) 55 } 56 57 for typ := range keybase1.HomeScreenTodoTypeRevMap { 58 switch typ { 59 case keybase1.HomeScreenTodoType_NONE: 60 require.Error(t, home.SkipTodoType(ctx, typ)) 61 default: 62 require.NoError(t, home.SkipTodoType(ctx, typ)) 63 } 64 } 65 66 require.NoError(t, home.MarkViewed(ctx)) 67 require.NoError(t, home.ActionTaken(ctx)) 68 } 69 70 func TestContactResolutionPeoplePage(t *testing.T) { 71 tc := libkb.SetupTest(t, "home", 2) 72 defer tc.Cleanup() 73 tc2 := libkb.SetupTest(t, "home", 2) 74 defer tc2.Cleanup() 75 76 // Make one user with two devices 77 u, err := kbtest.CreateAndSignupFakeUser("t", tc.G) 78 require.NoError(t, err) 79 err = u.Login(tc.G) 80 require.NoError(t, err) 81 kbtest.ProvisionNewDeviceKex(&tc, &tc2, u, keybase1.DeviceTypeV2_DESKTOP) 82 83 resolutions := []contacts.ContactResolution{{ 84 Description: "Jakob - (216) 555-2222", 85 ResolvedUser: keybase1.User{ 86 Uid: keybase1.UID("34"), 87 Username: "jakob223", 88 }, 89 }} 90 91 // Send resolution to server 92 err = contacts.SendEncryptedContactResolutionToServer(tc.MetaContext(), resolutions) 93 require.NoError(t, err) 94 95 // Get people page from server as second device, 96 // check it has the right contents 97 h := NewHome(tc2.G) 98 err = h.getToCache(tc2.MetaContext().Ctx(), false, 0, true) 99 require.NoError(t, err) 100 require.Len(t, h.homeCache.obj.Items, 3) 101 item := h.homeCache.obj.Items[2].Data.People().Contact() 102 require.Equal(t, resolutions[0].Description, item.Description) 103 require.Equal(t, resolutions[0].ResolvedUser.Username, item.Username) 104 }