5
5
CeramicContextProvider ,
6
6
CeramicContextState ,
7
7
cleanPassport ,
8
- getStampsToRetry ,
9
8
} from "../../context/ceramicContext" ;
10
- import { ComposeDatabase , PassportDatabase } from "@gitcoin/passport-database-client" ;
9
+ import { PassportDatabase } from "@gitcoin/passport-database-client" ;
11
10
import { useEffect } from "react" ;
12
11
import {
13
12
googleStampFixture ,
@@ -696,20 +695,8 @@ const passportDbMocks = {
696
695
did : "test-user-did" ,
697
696
} ;
698
697
699
- const ceramicDbMocks = {
700
- createPassport : dbCreatePassportMock ,
701
- getPassport : dbGetPassportMock ,
702
- addStamp : dbAddStampMock ,
703
- addStamps : dbAddStampsMock ,
704
- deleteStamp : dbDeleteStampMock ,
705
- deleteStamps : dbDeleteStampsMock ,
706
- patchStamps : vi . fn ( ) ,
707
- did : "test-user-did" ,
708
- } ;
709
-
710
698
vi . mock ( "@gitcoin/passport-database-client" , ( ) => {
711
699
return {
712
- ComposeDatabase : vi . fn ( ) . mockImplementation ( ( ) => ceramicDbMocks ) ,
713
700
PassportDatabase : vi . fn ( ) . mockImplementation ( ( ) => passportDbMocks ) ,
714
701
} ;
715
702
} ) ;
@@ -765,20 +752,6 @@ describe("CeramicContextProvider", () => {
765
752
} ) ,
766
753
} as any ;
767
754
} ) ;
768
- vi . mocked ( ComposeDatabase ) . mockImplementation ( ( ) => {
769
- return {
770
- ...ceramicDbMocks ,
771
- getPassport : vi . fn ( ) . mockImplementation ( async ( ) => {
772
- return {
773
- passport : {
774
- stamps : composeStamps ,
775
- } ,
776
- errorDetails : { } ,
777
- status : "Success" ,
778
- } ;
779
- } ) ,
780
- } as any ;
781
- } ) ;
782
755
783
756
const Component = ( ) => {
784
757
useEffect ( ( ) => {
@@ -813,9 +786,7 @@ describe("CeramicContextProvider", () => {
813
786
} ) ;
814
787
815
788
describe ( "CeramicContextProvider syncs stamp state with ceramic" , ( ) => {
816
- beforeEach ( ( ) => {
817
- vi . mocked ( ComposeDatabase ) . mockImplementation ( ( ) => ceramicDbMocks as any ) ;
818
- } ) ;
789
+ beforeEach ( ( ) => { } ) ;
819
790
820
791
it ( "should return passport and stamps after successful fetch" , async ( ) => {
821
792
vi . mocked ( PassportDatabase ) . mockImplementation ( ( ) => {
@@ -902,83 +873,13 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
902
873
} ) ,
903
874
} as any ;
904
875
} ) ;
905
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
906
- return {
907
- ...ceramicDbMocks ,
908
- getPassport : vi . fn ( ) . mockImplementation ( async ( ) => {
909
- return {
910
- passport : {
911
- stamps,
912
- } ,
913
- errorDetails : { } ,
914
- status : "Success" ,
915
- } ;
916
- } ) ,
917
- } as any ;
918
- } ) ;
876
+
919
877
render ( mockComponent ( ) ) ;
920
878
921
879
await waitFor ( ( ) => expect ( screen . getAllByText ( "# Stamps = 3" ) ) . toHaveLength ( 1 ) ) ;
922
880
} ) ;
923
881
924
- it ( "should attempt to add stamps to database and ceramic" , async ( ) => {
925
- const oldConsoleLog = console . log ;
926
- try {
927
- console . log = vi . fn ( ) ;
928
-
929
- const addStampsMock = vi . fn ( ) ;
930
- const addStampMock = vi . fn ( ) . mockRejectedValue ( new Error ( "Error" ) ) ;
931
- vi . mocked ( PassportDatabase ) . mockImplementationOnce ( ( ) => {
932
- return {
933
- ...passportDbMocks ,
934
- addStamps : addStampsMock . mockImplementationOnce ( async ( ) => {
935
- return {
936
- passport : {
937
- stamps,
938
- } ,
939
- errorDetails : { } ,
940
- status : "Success" ,
941
- } ;
942
- } ) ,
943
- getPassport : vi . fn ( ) . mockImplementationOnce ( async ( ) => {
944
- return {
945
- passport : {
946
- stamps : [ ] ,
947
- } ,
948
- errorDetails : { } ,
949
- status : "Success" ,
950
- } ;
951
- } ) ,
952
- } as any ;
953
- } ) ;
954
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
955
- return {
956
- ...ceramicDbMocks ,
957
- getPassport : vi . fn ( ) . mockImplementation ( async ( ) => {
958
- return {
959
- passport : {
960
- stamps,
961
- } ,
962
- errorDetails : { } ,
963
- status : "Success" ,
964
- } ;
965
- } ) ,
966
- addStamps : addStampMock ,
967
- } as any ;
968
- } ) ;
969
- render ( mockComponent ( ) ) ;
970
-
971
- await waitFor ( ( ) => fireEvent . click ( screen . getByText ( "handleAddStamps" ) ) ) ;
972
- await waitFor ( ( ) => {
973
- expect ( addStampsMock ) . toHaveBeenCalled ( ) ;
974
- expect ( addStampMock ) . toHaveBeenCalledWith ( stamps ) ;
975
- expect ( console . log ) . toHaveBeenCalledWith ( "error adding ceramic stamps" , new Error ( "Error" ) ) ;
976
- } ) ;
977
- } finally {
978
- console . log = oldConsoleLog ;
979
- }
980
- } ) ;
981
- it ( "should attempt to delete stamps from database and ceramic" , async ( ) => {
882
+ it ( "should attempt to delete stamps from database" , async ( ) => {
982
883
const oldConsoleLog = console . log ;
983
884
try {
984
885
console . log = vi . fn ( ) ;
@@ -1006,12 +907,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
1006
907
} ) ,
1007
908
} as any ;
1008
909
} ) ;
1009
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
1010
- return {
1011
- ...ceramicDbMocks ,
1012
- deleteStamps : deleteStampsMock ,
1013
- } as any ;
1014
- } ) ;
910
+
1015
911
render ( mockComponent ( ) ) ;
1016
912
1017
913
await waitFor ( ( ) => fireEvent . click ( screen . getByText ( "handleDeleteStamps" ) ) ) ;
@@ -1024,7 +920,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
1024
920
}
1025
921
} ) ;
1026
922
1027
- it ( "should patch stamps in database and delete + add stamps in ceramic " , async ( ) => {
923
+ it ( "should patch stamps in database" , async ( ) => {
1028
924
const added = stampPatches . filter ( ( { credential } ) => credential ) ;
1029
925
1030
926
const patchStampsMock = vi . fn ( ) ;
@@ -1055,13 +951,6 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
1055
951
const setStampMock = vi . fn ( ) ;
1056
952
const deleteStampsMock = vi . fn ( ) ;
1057
953
1058
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
1059
- return {
1060
- ...ceramicDbMocks ,
1061
- deleteStampIDs : deleteStampsMock ,
1062
- } as any ;
1063
- } ) ;
1064
-
1065
954
render ( mockComponent ( ) ) ;
1066
955
1067
956
await waitFor ( ( ) => fireEvent . click ( screen . getByText ( "handlePatchStamps" ) ) ) ;
@@ -1070,61 +959,8 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
1070
959
} ) ;
1071
960
} ) ;
1072
961
1073
- it ( "should log an error but continue if ceramic patch fails" , async ( ) => {
1074
- const oldConsoleLog = console . log ;
1075
- try {
1076
- console . log = vi . fn ( ) ;
1077
-
1078
- const patchStampsMock = vi . fn ( ) . mockRejectedValue ( new Error ( "Error" ) ) ;
1079
- vi . mocked ( PassportDatabase ) . mockImplementationOnce ( ( ) => {
1080
- return {
1081
- ...passportDbMocks ,
1082
- patchStamps : patchStampsMock . mockImplementationOnce ( async ( ) => {
1083
- return {
1084
- passport : {
1085
- stamps,
1086
- } ,
1087
- errorDetails : { } ,
1088
- status : "Success" ,
1089
- } ;
1090
- } ) ,
1091
- getPassport : vi . fn ( ) . mockImplementationOnce ( async ( ) => {
1092
- return {
1093
- passport : {
1094
- stamps,
1095
- } ,
1096
- errorDetails : { } ,
1097
- status : "Success" ,
1098
- } ;
1099
- } ) ,
1100
- } as any ;
1101
- } ) ;
1102
-
1103
- const setStampMock = vi . fn ( ) . mockRejectedValue ( new Error ( "Error" ) ) ;
1104
- const deleteStampsMock = vi . fn ( ) ;
1105
-
1106
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
1107
- return {
1108
- ...ceramicDbMocks ,
1109
- setStamps : setStampMock ,
1110
- deleteStampIDs : deleteStampsMock ,
1111
- patchStamps : patchStampsMock ,
1112
- } as any ;
1113
- } ) ;
1114
-
1115
- render ( mockComponent ( ) ) ;
1116
-
1117
- await waitFor ( ( ) => fireEvent . click ( screen . getByText ( "handlePatchStamps" ) ) ) ;
1118
- await waitFor ( ( ) => {
1119
- expect ( patchStampsMock ) . toHaveBeenCalledWith ( stampPatches ) ;
1120
- expect ( console . log ) . toHaveBeenCalledWith ( "error patching ceramic stamps" , new Error ( "Error" ) ) ;
1121
- } ) ;
1122
- } finally {
1123
- console . log = oldConsoleLog ;
1124
- }
1125
- } ) ;
1126
-
1127
- it ( "should show an error toast but continue if ceramic patch fails due to invalid session" , async ( ) => {
962
+ it ( "should patch stamps with PasportDatabase" , async ( ) => {
963
+ const patchStampsMock = vi . fn ( ) . mockRejectedValue ( new Error ( "Error" ) ) ;
1128
964
vi . mocked ( PassportDatabase ) . mockImplementationOnce ( ( ) => {
1129
965
return {
1130
966
...passportDbMocks ,
@@ -1149,22 +985,14 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
1149
985
} as any ;
1150
986
} ) ;
1151
987
1152
- const patchStampsMock = vi . fn ( ) ;
988
+ vi . fn ( ) . mockRejectedValue ( new Error ( "Error" ) ) ;
1153
989
1154
- vi . mocked ( ComposeDatabase ) . mockImplementationOnce ( ( ) => {
1155
- return {
1156
- ...ceramicDbMocks ,
1157
- patchStamps : patchStampsMock ,
1158
- } as any ;
1159
- } ) ;
1160
-
1161
- render ( mockComponent ( { invalidSession : true } ) ) ;
990
+ render ( mockComponent ( ) ) ;
1162
991
1163
992
await waitFor ( ( ) => fireEvent . click ( screen . getByText ( "handlePatchStamps" ) ) ) ;
1164
- await waitFor ( ( ) => expect ( patchStampsMock ) . toHaveBeenCalledWith ( stampPatches ) ) ;
1165
- await screen . findByText (
1166
- "Your update was not logged to Ceramic. Please refresh the page to reset your Ceramic session."
1167
- ) ;
993
+ await waitFor ( ( ) => {
994
+ expect ( patchStampsMock ) . toHaveBeenCalledWith ( stampPatches ) ;
995
+ } ) ;
1168
996
} ) ;
1169
997
} ) ;
1170
998
@@ -1220,14 +1048,3 @@ describe("cleanPassport function", () => {
1220
1048
expect ( result . expiredProviders . length ) . toBe ( 0 ) ;
1221
1049
} ) ;
1222
1050
} ) ;
1223
-
1224
- describe ( "handleComposeRetry function" , ( ) => {
1225
- it ( "should detect a difference between the stamps in the database and the stamps in ceramic" , async ( ) => {
1226
- const result = getStampsToRetry ( composeStamps , databasePassport . stamps ) ;
1227
- expect ( result ) . toHaveLength ( 2 ) ;
1228
- } ) ;
1229
- it ( "should not return anything if the stamps in the database and the stamps in ceramic are the same" , async ( ) => {
1230
- const result = getStampsToRetry ( databasePassport . stamps , databasePassport . stamps ) ;
1231
- expect ( result ) . toHaveLength ( 0 ) ;
1232
- } ) ;
1233
- } ) ;
0 commit comments