1
+ package org .lowcoder .api .usermanagement ;
2
+
3
+ import org .junit .jupiter .api .Assertions ;
4
+ import org .junit .jupiter .api .BeforeEach ;
5
+ import org .junit .jupiter .api .Test ;
6
+ import org .lowcoder .api .common .mockuser .WithMockUser ;
7
+ import org .lowcoder .domain .invitation .model .Invitation ;
8
+ import org .lowcoder .domain .invitation .repository .InvitationRepository ;
9
+ import org .lowcoder .domain .organization .model .Organization ;
10
+ import org .lowcoder .domain .organization .model .OrganizationState ;
11
+ import org .lowcoder .domain .organization .repository .OrganizationRepository ;
12
+ import org .lowcoder .domain .user .model .User ;
13
+ import org .lowcoder .domain .user .repository .UserRepository ;
14
+ import org .springframework .beans .factory .annotation .Autowired ;
15
+ import org .springframework .boot .test .context .SpringBootTest ;
16
+ import reactor .test .StepVerifier ;
17
+
18
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
19
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
20
+
21
+ @ SpringBootTest
22
+ public class InvitationApiServiceImplIntegrationTest {
23
+
24
+ @ Autowired
25
+ private InvitationApiService invitationApiService ;
26
+
27
+ @ Autowired
28
+ private InvitationRepository invitationRepository ;
29
+
30
+ @ Autowired
31
+ private OrganizationRepository organizationRepository ;
32
+
33
+ @ Autowired
34
+ private UserRepository userRepository ;
35
+
36
+ private User testUser ;
37
+ private Organization testOrganization ;
38
+ private Invitation testInvitation ;
39
+
40
+ @ BeforeEach
41
+ public void setUp () {
42
+ // Create and save test user
43
+ testUser = new User ();
44
+ testUser .setId ("testuserid" );
45
+ testUser .setName ("Test User" );
46
+ userRepository .save (testUser ).block ();
47
+
48
+ // Create and save test organization
49
+ testOrganization = new Organization ();
50
+ testOrganization .setId ("testorgid" );
51
+ testOrganization .setName ("Test Organization" );
52
+ testOrganization .setState (OrganizationState .ACTIVE );
53
+ organizationRepository .save (testOrganization ).block ();
54
+
55
+ // Create and save test invitation
56
+ testInvitation = Invitation .builder ()
57
+ .createUserId (testUser .getId ())
58
+ .invitedOrganizationId (testOrganization .getId ())
59
+ .build ();
60
+ testInvitation .setId ("testinvitationid" );
61
+ invitationRepository .save (testInvitation ).block ();
62
+
63
+ // Create and save test invitation - no org
64
+ Invitation testInvitation1 = Invitation .builder ()
65
+ .createUserId (testUser .getId ())
66
+ .invitedOrganizationId ("notfoundorg" )
67
+ .build ();
68
+ testInvitation1 .setId ("testinvitationid2noorg" );
69
+ invitationRepository .save (testInvitation1 ).block ();
70
+ }
71
+
72
+ @ Test
73
+ public void testGetInvitationView_Success () {
74
+ StepVerifier .create (invitationApiService .getInvitationView (testInvitation .getId ()))
75
+ .assertNext (invitationVO -> {
76
+ assertEquals (testInvitation .getId (), invitationVO .getInviteCode ());
77
+ assertEquals (testOrganization .getId (), invitationVO .getInvitedOrganizationId ());
78
+ })
79
+ .verifyComplete ();
80
+ }
81
+
82
+ @ Test
83
+ public void testGetInvitationView_Failed_InviteCodeNotFound () {
84
+ StepVerifier .create (invitationApiService .getInvitationView ("notfoundcode" ))
85
+ .expectError ()
86
+ .verify ();
87
+ }
88
+
89
+ @ Test
90
+ @ WithMockUser
91
+ public void testCreate_Success () {
92
+ StepVerifier .create (invitationApiService .create (testOrganization .getId ()))
93
+ .assertNext (invitationVO -> {
94
+ assertEquals (testOrganization .getId (), invitationVO .getInvitedOrganizationId ());
95
+ })
96
+ .verifyComplete ();
97
+ }
98
+
99
+ @ Test
100
+ @ WithMockUser
101
+ public void testCreate_Failed () {
102
+ StepVerifier .create (invitationApiService .create ("notfoundid" ))
103
+ .expectError ()
104
+ .verify ();
105
+ }
106
+
107
+ @ Test
108
+ @ WithMockUser
109
+ public void testInviteUser_Success () {
110
+ StepVerifier .create (invitationApiService .inviteUser (testInvitation .getId ()))
111
+ .assertNext (Assertions ::assertTrue )
112
+ .verifyComplete ();
113
+
114
+ StepVerifier .create (invitationApiService .inviteUser (testInvitation .getId ()))
115
+ .expectError ()
116
+ .verify ();
117
+ }
118
+
119
+ @ Test
120
+ @ WithMockUser
121
+ public void testInviteUser_Failed_CodeNotFound () {
122
+ StepVerifier .create (invitationApiService .inviteUser ("testinvitationid2noorg" ))
123
+ .expectError ()
124
+ .verify ();
125
+ }
126
+ }
0 commit comments