1- import { RaffleService } from ' ./raffle.service' ;
2- import { ContractService } from ' ../../contract/contract.service' ;
3- import { ContractFn } from ' ../../contract/bindings' ;
4- import { RaffleParams , RaffleData } from ' ./raffle.types' ;
5- import { nativeToScVal } from ' @stellar/stellar-sdk' ;
1+ import { RaffleService } from " ./raffle.service" ;
2+ import { ContractService } from " ../../contract/contract.service" ;
3+ import { ContractFn } from " ../../contract/bindings" ;
4+ import { RaffleParams , RaffleData } from " ./raffle.types" ;
5+ import { nativeToScVal } from " @stellar/stellar-sdk" ;
66
7- describe ( ' RaffleService' , ( ) => {
7+ describe ( " RaffleService" , ( ) => {
88 let service : RaffleService ;
99 let contractService : jest . Mocked < ContractService > ;
1010
@@ -18,20 +18,20 @@ describe('RaffleService', () => {
1818 service = new RaffleService ( contractService ) ;
1919 } ) ;
2020
21- describe ( ' create' , ( ) => {
22- it ( ' should correctly format and invoke CREATE_RAFFLE' , async ( ) => {
21+ describe ( " create" , ( ) => {
22+ it ( " should correctly format and invoke CREATE_RAFFLE" , async ( ) => {
2323 const params : RaffleParams = {
24- ticketPrice : '10' ,
24+ ticketPrice : "10" ,
2525 maxTickets : 100 ,
2626 endTime : Date . now ( ) + 86400000 , // +1 day
2727 allowMultiple : true ,
28- asset : ' XLM' ,
29- metadataCid : ' QmTest' ,
28+ asset : " XLM" ,
29+ metadataCid : " QmTest" ,
3030 } ;
3131
3232 const mockInvokeResult = {
3333 result : 1 ,
34- txHash : ' abc' ,
34+ txHash : " abc" ,
3535 ledger : 100 ,
3636 } ;
3737
@@ -42,51 +42,57 @@ describe('RaffleService', () => {
4242 expect ( contractService . invoke ) . toHaveBeenCalledWith (
4343 ContractFn . CREATE_RAFFLE ,
4444 expect . any ( Array ) ,
45+ expect . anything ( ) , // Add this to handle the metadata object
4546 ) ;
47+
4648 expect ( result ) . toEqual ( {
4749 raffleId : 1 ,
48- txHash : ' abc' ,
50+ txHash : " abc" ,
4951 ledger : 100 ,
5052 } ) ;
5153 } ) ;
5254
53- it ( ' should throw if ticketPrice is empty' , async ( ) => {
55+ it ( " should throw if ticketPrice is empty" , async ( ) => {
5456 const params : RaffleParams = {
55- ticketPrice : '' ,
57+ ticketPrice : "" ,
5658 maxTickets : 100 ,
5759 endTime : Date . now ( ) ,
5860 allowMultiple : true ,
59- asset : ' XLM' ,
61+ asset : " XLM" ,
6062 } ;
6163
62- await expect ( service . create ( params ) ) . rejects . toThrow ( 'ticketPrice must be a non-empty string' ) ;
64+ await expect ( service . create ( params ) ) . rejects . toThrow (
65+ "ticketPrice must be a non-empty string" ,
66+ ) ;
6367 } ) ;
6468
65- it ( ' should throw if maxTickets is not a positive integer' , async ( ) => {
69+ it ( " should throw if maxTickets is not a positive integer" , async ( ) => {
6670 const params : RaffleParams = {
67- ticketPrice : '10' ,
71+ ticketPrice : "10" ,
6872 maxTickets : 0 ,
6973 endTime : Date . now ( ) ,
7074 allowMultiple : true ,
71- asset : ' XLM' ,
75+ asset : " XLM" ,
7276 } ;
7377
74- await expect ( service . create ( params ) ) . rejects . toThrow ( 'maxTickets must be a positive integer' ) ;
78+ await expect ( service . create ( params ) ) . rejects . toThrow (
79+ "maxTickets must be a positive integer" ,
80+ ) ;
7581 } ) ;
7682 } ) ;
7783
78- describe ( ' get' , ( ) => {
79- it ( ' should fetch and map raffle data' , async ( ) => {
84+ describe ( " get" , ( ) => {
85+ it ( " should fetch and map raffle data" , async ( ) => {
8086 const mockRawData = {
81- creator : ' G...' ,
87+ creator : " G..." ,
8288 status : 1 , // OPEN
8389 ticket_price : BigInt ( 100000000 ) ,
8490 max_tickets : 100 ,
8591 tickets_sold : 50 ,
8692 end_time : BigInt ( 1711545600 ) , // example timestamp in seconds
87- asset : ' XLM' ,
93+ asset : " XLM" ,
8894 allow_multiple : true ,
89- metadata_cid : ' Qm...' ,
95+ metadata_cid : " Qm..." ,
9096 } ;
9197
9298 contractService . simulateReadOnly . mockResolvedValue ( mockRawData ) ;
@@ -99,18 +105,20 @@ describe('RaffleService', () => {
99105 [ raffleId ] ,
100106 ) ;
101107 expect ( result . raffleId ) . toBe ( raffleId ) ;
102- expect ( result . ticketPrice ) . toBe ( ' 100000000' ) ;
108+ expect ( result . ticketPrice ) . toBe ( " 100000000" ) ;
103109 expect ( result . maxTickets ) . toBe ( 100 ) ;
104110 expect ( result . endTime ) . toBe ( 1711545600 * 1000 ) ;
105111 } ) ;
106112
107- it ( 'should throw if raffleId is invalid' , async ( ) => {
108- await expect ( service . get ( - 1 ) ) . rejects . toThrow ( 'raffleId must be a positive integer' ) ;
113+ it ( "should throw if raffleId is invalid" , async ( ) => {
114+ await expect ( service . get ( - 1 ) ) . rejects . toThrow (
115+ "raffleId must be a positive integer" ,
116+ ) ;
109117 } ) ;
110118 } ) ;
111119
112- describe ( ' listActive' , ( ) => {
113- it ( ' should return active raffle IDs' , async ( ) => {
120+ describe ( " listActive" , ( ) => {
121+ it ( " should return active raffle IDs" , async ( ) => {
114122 const mockIds = [ 1 , 2 , 3 ] ;
115123 contractService . simulateReadOnly . mockResolvedValue ( mockIds ) ;
116124
@@ -124,8 +132,8 @@ describe('RaffleService', () => {
124132 } ) ;
125133 } ) ;
126134
127- describe ( ' listAll' , ( ) => {
128- it ( ' should return all raffle IDs' , async ( ) => {
135+ describe ( " listAll" , ( ) => {
136+ it ( " should return all raffle IDs" , async ( ) => {
129137 const mockIds = [ 1 , 2 , 3 , 4 ] ;
130138 contractService . simulateReadOnly . mockResolvedValue ( mockIds ) ;
131139
@@ -139,22 +147,22 @@ describe('RaffleService', () => {
139147 } ) ;
140148 } ) ;
141149
142- describe ( ' cancel' , ( ) => {
143- it ( ' should invoke CANCEL_RAFFLE' , async ( ) => {
150+ describe ( " cancel" , ( ) => {
151+ it ( " should invoke CANCEL_RAFFLE" , async ( ) => {
144152 const mockInvokeResult = {
145153 result : undefined ,
146- txHash : ' hash' ,
154+ txHash : " hash" ,
147155 ledger : 200 ,
148156 } ;
149157
150158 contractService . invoke . mockResolvedValue ( mockInvokeResult ) ;
151159
152160 const raffleId = 1 ;
153- const result = await service . cancel ( raffleId ) ;
154-
161+ const result = await service . cancel ( { raffleId } ) ;
155162 expect ( contractService . invoke ) . toHaveBeenCalledWith (
156163 ContractFn . CANCEL_RAFFLE ,
157164 [ raffleId ] ,
165+ expect . anything ( ) , // Add this to handle the metadata object
158166 ) ;
159167 expect ( result ) . toEqual ( mockInvokeResult ) ;
160168 } ) ;
0 commit comments