Skip to content

Commit dadb3b4

Browse files
authored
Merge branch 'dev' into meta_api
2 parents 41d668c + e96bf13 commit dadb3b4

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

server/api-service/lowcoder-server/src/test/java/org/lowcoder/api/service/OrganizationServiceTest.java

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.boot.test.context.SpringBootTest;
1313
import org.springframework.test.context.ActiveProfiles;
14+
import reactor.core.publisher.Flux;
1415
import reactor.core.publisher.Mono;
1516
import reactor.test.StepVerifier;
1617

18+
import java.util.List;
19+
import java.util.UUID;
20+
1721
@SpringBootTest
1822
//@RunWith(SpringRunner.class)
1923
@ActiveProfiles("OrganizationApiServiceTest")
@@ -28,6 +32,7 @@ public class OrganizationServiceTest {
2832
private Mono<Organization> createOrganization(String name) {
2933
Organization organization = Organization.builder()
3034
.name(name)
35+
.gid("gid-" + UUID.randomUUID())
3136
.build();
3237
return organizationService.create(organization, "user01", false);
3338
}
@@ -51,4 +56,133 @@ public void testUpdateSlug() {
5156
})
5257
.verifyComplete();
5358
}
59+
60+
@Test
61+
@WithMockUser
62+
public void testGetAllActive() {
63+
// Create a single organization to ensure there is at least one active one in the database
64+
Mono<Organization> orgMono = createOrganization("ActiveOrganization");
65+
66+
// Ensure the organization is created and then verify getAllActive
67+
Flux<Organization> allActiveOrganizations = orgMono.thenMany(organizationService.getAllActive());
68+
69+
StepVerifier.create(allActiveOrganizations.collectList())
70+
.assertNext(orgList -> {
71+
Assertions.assertFalse(orgList.isEmpty(), "The organization list should not be empty");
72+
Organization lastOrg = orgList.get(orgList.size() - 1);
73+
74+
// Check the last element in the list
75+
Assertions.assertNotNull(lastOrg.getId(), "Last organization ID should not be null");
76+
Assertions.assertEquals("ActiveOrganization", lastOrg.getName(), "Last organization name should match 'ActiveOrganization'");
77+
})
78+
.verifyComplete();
79+
}
80+
81+
@Test
82+
@WithMockUser
83+
public void testGetByIds() {
84+
// Create the first organization and update its gid
85+
Mono<Organization> org1Mono = createOrganization("Organization1")
86+
.flatMap(org -> {
87+
org.setGid("gid-1");
88+
return organizationService.update(org.getId(), org)
89+
.thenReturn(org);
90+
});
91+
92+
// Create the second organization and update its gid
93+
Mono<Organization> org2Mono = createOrganization("Organization2")
94+
.flatMap(org -> {
95+
org.setGid("gid-2");
96+
return organizationService.update(org.getId(), org)
97+
.thenReturn(org);
98+
});
99+
100+
// Use these updated organizations in further operations or assertions
101+
Flux<Organization> savedOrgs = org1Mono.then(org2Mono)
102+
.thenMany(organizationService.getByIds(List.of("gid-1", "gid-2")));
103+
104+
StepVerifier.create(savedOrgs.collectList())
105+
.assertNext(orgList -> {
106+
Assertions.assertTrue(orgList.size() >= 2, "Organization list should have at least two elements");
107+
108+
// Check the last two elements
109+
Organization org1 = orgList.get(orgList.size() - 2);
110+
Organization org2 = orgList.get(orgList.size() - 1);
111+
112+
Assertions.assertNotNull(org1.getId(), "Organization ID should not be null");
113+
Assertions.assertEquals("gid-1", org1.getGid(), "First organization GID should match 'gid-1'");
114+
Assertions.assertEquals("Organization1", org1.getName(), "First organization name should match 'Organization1'");
115+
116+
Assertions.assertNotNull(org2.getId(), "Organization ID should not be null");
117+
Assertions.assertEquals("gid-2", org2.getGid(), "Second organization GID should match 'gid-2'");
118+
Assertions.assertEquals("Organization2", org2.getName(), "Second organization name should match 'Organization2'");
119+
})
120+
.verifyComplete();
121+
}
122+
123+
@Test
124+
@WithMockUser
125+
public void testGetOrgCommonSettings() {
126+
127+
Organization.OrganizationCommonSettings testSettings = new Organization.OrganizationCommonSettings();
128+
testSettings.put("settingKey1", "settingValue1");
129+
testSettings.put("settingKey2", "settingValue2");
130+
131+
// Create the first organization and update its common setting
132+
Mono<Organization> orgMono = createOrganization("Organization")
133+
.flatMap(org -> {
134+
org.setCommonSettings(testSettings);
135+
return organizationService.update(org.getId(), org)
136+
.thenReturn(org);
137+
});
138+
139+
// Retrieve the common settings from the organization
140+
Mono<Organization.OrganizationCommonSettings> commonSettingsMono = orgMono
141+
.flatMap(org -> organizationService.getOrgCommonSettings(org.getId()));
142+
143+
// Verify that the settings match the expected test settings
144+
StepVerifier.create(commonSettingsMono)
145+
.assertNext(retrievedSettings -> {
146+
Assertions.assertEquals("settingValue1", retrievedSettings.get("settingKey1"), "The setting value for 'settingKey1' should match");
147+
Assertions.assertEquals("settingValue2", retrievedSettings.get("settingKey2"), "The setting value for 'settingKey2' should match");
148+
})
149+
.verifyComplete();
150+
}
151+
152+
@Test
153+
@WithMockUser
154+
public void testUpdateCommonSettings() {
155+
// Initial settings for the organization
156+
Organization.OrganizationCommonSettings initialSettings = new Organization.OrganizationCommonSettings();
157+
initialSettings.put("settingKey1", "initialValue1");
158+
159+
// Create an organization with initial settings
160+
Mono<Organization> orgMono = createOrganization("CommonSettingsTestOrganization")
161+
.flatMap(org -> {
162+
org.setCommonSettings(initialSettings);
163+
return organizationService.update(org.getId(), org)
164+
.thenReturn(org);
165+
});
166+
167+
// Define key and new value to update
168+
String keyToUpdate = "settingKey1";
169+
String newValue = "updatedValue1";
170+
171+
// Chain the update and verification operations
172+
orgMono.flatMap(org ->
173+
// Update the common settings
174+
organizationService.updateCommonSettings(org.getId(), keyToUpdate, newValue)
175+
.flatMap(updateSuccess -> {
176+
Assertions.assertTrue(updateSuccess, "Update should be successful");
177+
// Retrieve updated common settings
178+
return organizationService.getOrgCommonSettings(org.getId());
179+
})
180+
)
181+
.as(StepVerifier::create)
182+
.assertNext(updatedSettings -> {
183+
// Verify updated settings
184+
Assertions.assertEquals(newValue, updatedSettings.get(keyToUpdate), "The setting value should be updated to 'updatedValue1'");
185+
})
186+
.verifyComplete();
187+
}
54188
}

server/api-service/lowcoder-server/src/test/java/org/lowcoder/api/service/impl/ApplicationHistorySnapshotServiceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,9 @@ public void testServiceMethods() {
8484
})
8585
.verifyComplete();
8686

87+
StepVerifier.create(service.countByApplicationIdArchived(applicationId))
88+
.expectNext(0L)
89+
.verifyComplete();
90+
8791
}
8892
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy