24
24
import org .testcontainers .containers .RabbitMQContainer ;
25
25
import org .testcontainers .junit .jupiter .Container ;
26
26
import org .testcontainers .junit .jupiter .Testcontainers ;
27
+ import com .workup .shared .commands .payments .wallet .requests .CreateWalletRequest ;
28
+ import com .workup .shared .commands .payments .wallet .responses .CreateWalletResponse ;
29
+ import com .workup .shared .commands .payments .wallet .requests .GetWalletRequest ;
30
+ import com .workup .shared .commands .payments .wallet .responses .GetWalletResponse ;
27
31
28
32
@ SpringBootTest
29
33
@ Testcontainers
30
34
@ Import (TestConfigBase .class )
31
35
class PaymentsApplicationTests {
32
36
33
37
@ Container
34
- static final PostgreSQLContainer <?> postgreSQLContainer =
35
- new PostgreSQLContainer <>("postgres:latest" );
38
+ static final PostgreSQLContainer <?> postgreSQLContainer = new PostgreSQLContainer <>("postgres:latest" );
36
39
37
40
@ Container
38
- static final RabbitMQContainer rabbitMQContainer =
39
- new RabbitMQContainer ("rabbitmq:3.13-management" );
41
+ static final RabbitMQContainer rabbitMQContainer = new RabbitMQContainer ("rabbitmq:3.13-management" );
40
42
41
- @ Autowired private AmqpTemplate template ;
42
- @ Autowired private PaymentRequestRepository paymentRequestRepository ;
43
- @ Autowired private PaymentTransactionRepository paymentTransactionRepository ;
44
- @ Autowired private WalletRepository walletRepository ;
45
- @ Autowired private WalletTransactionRepository walletTransactionRepository ;
43
+ @ Autowired
44
+ private AmqpTemplate template ;
45
+ @ Autowired
46
+ private PaymentRequestRepository paymentRequestRepository ;
47
+ @ Autowired
48
+ private PaymentTransactionRepository paymentTransactionRepository ;
49
+ @ Autowired
50
+ private WalletRepository walletRepository ;
51
+ @ Autowired
52
+ private WalletTransactionRepository walletTransactionRepository ;
46
53
47
54
@ BeforeEach
48
55
void clearAll () {
@@ -73,16 +80,14 @@ static void setDatasourceProperties(DynamicPropertyRegistry registry) {
73
80
74
81
@ Test
75
82
void testCreatePaymentRequest () {
76
- CreatePaymentRequestRequest createPaymentRequest =
77
- CreatePaymentRequestRequest .builder ()
78
- .withAmount (1200 )
79
- .withDescription ("Payment for services rendered" )
80
- .withClientId ("3" )
81
- .withFreelancerId ("4" )
82
- .build ();
83
- CreatePaymentRequestResponse response =
84
- (CreatePaymentRequestResponse )
85
- template .convertSendAndReceive (ServiceQueueNames .PAYMENTS , createPaymentRequest );
83
+ CreatePaymentRequestRequest createPaymentRequest = CreatePaymentRequestRequest .builder ()
84
+ .withAmount (1200 )
85
+ .withDescription ("Payment for services rendered" )
86
+ .withClientId ("3" )
87
+ .withFreelancerId ("4" )
88
+ .build ();
89
+ CreatePaymentRequestResponse response = (CreatePaymentRequestResponse ) template
90
+ .convertSendAndReceive (ServiceQueueNames .PAYMENTS , createPaymentRequest );
86
91
87
92
assertNotNull (response );
88
93
assertEquals (HttpStatusCode .CREATED , response .getStatusCode ());
@@ -98,4 +103,65 @@ void testCreatePaymentRequest() {
98
103
},
99
104
() -> fail ("Payment request not found" ));
100
105
}
106
+
107
+ @ Test
108
+ void testCreateWalletCommand () {
109
+
110
+ CreateWalletRequest createWalletRequest = CreateWalletRequest .builder ()
111
+ .withFreelancerId ("1" )
112
+ .build ();
113
+ CreateWalletResponse response = (CreateWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
114
+ createWalletRequest );
115
+ assertNotNull (response );
116
+ assertEquals (HttpStatusCode .CREATED , response .getStatusCode ());
117
+
118
+ }
119
+
120
+ @ Test
121
+ void testCreateDuplicateWalletIsInvalid () {
122
+ CreateWalletRequest createWalletRequest = CreateWalletRequest .builder ()
123
+ .withFreelancerId ("1" )
124
+ .build ();
125
+ CreateWalletResponse response = (CreateWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
126
+ createWalletRequest );
127
+ assertNotNull (response );
128
+ assertEquals (HttpStatusCode .CREATED , response .getStatusCode ());
129
+
130
+ CreateWalletResponse response2 = (CreateWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
131
+ createWalletRequest );
132
+ assertNotNull (response2 );
133
+ assertEquals (HttpStatusCode .BAD_REQUEST , response2 .getStatusCode ());
134
+ }
135
+
136
+ @ Test
137
+ void testGetValidWallet () {
138
+ CreateWalletRequest createWalletRequest = CreateWalletRequest .builder ()
139
+ .withFreelancerId ("1" )
140
+ .build ();
141
+ CreateWalletResponse response = (CreateWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
142
+ createWalletRequest );
143
+ assertNotNull (response );
144
+ assertEquals (HttpStatusCode .CREATED , response .getStatusCode ());
145
+
146
+ GetWalletRequest getWalletRequest = GetWalletRequest .builder ()
147
+ .withFreelancerId ("1" )
148
+ .build ();
149
+ GetWalletResponse getWalletResponse = (GetWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
150
+ getWalletRequest );
151
+ assertNotNull (getWalletResponse );
152
+ assertEquals (HttpStatusCode .OK , getWalletResponse .getStatusCode ());
153
+ assertEquals (0 , getWalletResponse .getBalance ());
154
+ }
155
+
156
+ @ Test
157
+ void testGetInvalidWallet () {
158
+ GetWalletRequest getWalletRequest = GetWalletRequest .builder ()
159
+ .withFreelancerId ("1" )
160
+ .build ();
161
+ GetWalletResponse getWalletResponse = (GetWalletResponse ) template .convertSendAndReceive (ServiceQueueNames .PAYMENTS ,
162
+ getWalletRequest );
163
+ assertNotNull (getWalletResponse );
164
+ assertEquals (HttpStatusCode .NOT_FOUND , getWalletResponse .getStatusCode ());
165
+ }
166
+
101
167
}
0 commit comments