@@ -12,6 +12,13 @@ describe("getDispute", () => {
12
12
const mockCoreSubgraph = "https://api.thegraph.com/subgraphs/name/kleros/core" ;
13
13
const mockDtrSubgraph = "https://api.thegraph.com/subgraphs/name/kleros/dtr" ;
14
14
15
+ const standardRefuseToArbitrateAnswer = {
16
+ id : "0x0" ,
17
+ title : "Refuse to Arbitrate / Invalid" ,
18
+ description : "Refuse to Arbitrate / Invalid" ,
19
+ reserved : true ,
20
+ } ;
21
+
15
22
const mockDisputeDetails = {
16
23
dispute : {
17
24
templateId : 1 ,
@@ -52,12 +59,7 @@ describe("getDispute", () => {
52
59
} ) ;
53
60
54
61
expect ( result ?. answers ) . toHaveLength ( 1 ) ;
55
- expect ( result ?. answers [ 0 ] ) . toEqual ( {
56
- id : "0x0" ,
57
- title : "Refuse to Arbitrate / Invalid" ,
58
- description : "Refuse to Arbitrate / Invalid" ,
59
- reserved : true ,
60
- } ) ;
62
+ expect ( result ?. answers [ 0 ] ) . toEqual ( standardRefuseToArbitrateAnswer ) ;
61
63
} ) ;
62
64
63
65
it ( "should add Refuse to Arbitrate option when it doesn't exist in answers" , async ( ) => {
@@ -98,18 +100,14 @@ describe("getDispute", () => {
98
100
} ) ;
99
101
100
102
expect ( result ?. answers ) . toHaveLength ( 3 ) ;
101
- expect ( result ?. answers [ 0 ] ) . toEqual ( {
102
- id : "0x0" ,
103
- title : "Refuse to Arbitrate / Invalid" ,
104
- description : "Refuse to Arbitrate / Invalid" ,
105
- reserved : true ,
106
- } ) ;
103
+ expect ( result ?. answers [ 0 ] ) . toEqual ( standardRefuseToArbitrateAnswer ) ;
107
104
expect ( result ?. answers [ 1 ] . id ) . toBe ( "0x1" ) ;
108
105
expect ( result ?. answers [ 2 ] . id ) . toBe ( "0x2" ) ;
109
106
} ) ;
110
107
111
- it ( "should not add Refuse to Arbitrate option when it already exists with id 0x0" , async ( ) => {
112
- const mockTemplate = {
108
+ it ( "should overwrite existing answer with id 0x0 or 0x00" , async ( ) => {
109
+ // Test with 0x0
110
+ const mockTemplate0x0 = {
113
111
disputeTemplate : {
114
112
templateData : JSON . stringify ( {
115
113
title : "Test Dispute" ,
@@ -118,8 +116,8 @@ describe("getDispute", () => {
118
116
answers : [
119
117
{
120
118
id : "0x0" ,
121
- title : "Refuse to Arbitrate / Invalid " ,
122
- description : "Refuse to Arbitrate / Invalid " ,
119
+ title : "Custom Refuse Title " ,
120
+ description : "Custom Refuse Description " ,
123
121
reserved : true ,
124
122
} ,
125
123
{
@@ -138,21 +136,20 @@ describe("getDispute", () => {
138
136
} ;
139
137
140
138
vi . mocked ( fetchDisputeDetails ) . mockResolvedValue ( mockDisputeDetails ) ;
141
- vi . mocked ( fetchDisputeTemplateFromId ) . mockResolvedValue ( mockTemplate ) ;
139
+ vi . mocked ( fetchDisputeTemplateFromId ) . mockResolvedValue ( mockTemplate0x0 ) ;
142
140
143
- const result = await getDispute ( {
141
+ let result = await getDispute ( {
144
142
disputeId : mockDisputeId ,
145
143
coreSubgraph : mockCoreSubgraph ,
146
144
dtrSubgraph : mockDtrSubgraph ,
147
145
} ) ;
148
146
149
147
expect ( result ?. answers ) . toHaveLength ( 2 ) ;
150
- expect ( result ?. answers [ 0 ] . id ) . toBe ( "0x0" ) ;
148
+ expect ( result ?. answers [ 0 ] ) . toEqual ( standardRefuseToArbitrateAnswer ) ;
151
149
expect ( result ?. answers [ 1 ] . id ) . toBe ( "0x1" ) ;
152
- } ) ;
153
150
154
- it ( "should not add Refuse to Arbitrate option when it already exists with id 0x00" , async ( ) => {
155
- const mockTemplate = {
151
+ // Test with 0x00
152
+ const mockTemplate0x00 = {
156
153
disputeTemplate : {
157
154
templateData : JSON . stringify ( {
158
155
title : "Test Dispute" ,
@@ -180,18 +177,16 @@ describe("getDispute", () => {
180
177
} ,
181
178
} ;
182
179
183
- vi . mocked ( fetchDisputeDetails ) . mockResolvedValue ( mockDisputeDetails ) ;
184
- vi . mocked ( fetchDisputeTemplateFromId ) . mockResolvedValue ( mockTemplate ) ;
180
+ vi . mocked ( fetchDisputeTemplateFromId ) . mockResolvedValue ( mockTemplate0x00 ) ;
185
181
186
- const result = await getDispute ( {
182
+ result = await getDispute ( {
187
183
disputeId : mockDisputeId ,
188
184
coreSubgraph : mockCoreSubgraph ,
189
185
dtrSubgraph : mockDtrSubgraph ,
190
186
} ) ;
191
187
192
188
expect ( result ?. answers ) . toHaveLength ( 2 ) ;
193
- expect ( result ?. answers [ 0 ] . id ) . toBe ( "0x00" ) ;
194
- expect ( result ?. answers [ 0 ] . title ) . toBe ( "Custom Refuse Title" ) ;
189
+ expect ( result ?. answers [ 0 ] ) . toEqual ( standardRefuseToArbitrateAnswer ) ;
195
190
expect ( result ?. answers [ 1 ] . id ) . toBe ( "0x1" ) ;
196
191
} ) ;
197
192
0 commit comments