Skip to content

Commit 461be6a

Browse files
Thomasludomikula
Thomas
authored andcommitted
Create a bundle create test
1 parent 7b86625 commit 461be6a

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ public class BundleApiServiceImpl implements BundleApiService {
8989
@Override
9090
public Mono<BundleInfoView> create(CreateBundleRequest createBundleRequest) {
9191
Bundle bundle = Bundle.builder()
92+
.organizationId(createBundleRequest.organizationId())
9293
.name(createBundleRequest.name())
9394
.image(createBundleRequest.image())
9495
.title(createBundleRequest.title())
9596
.description(createBundleRequest.description())
96-
.category(createBundleRequest.description())
97+
.category(createBundleRequest.category())
9798
.bundleStatus(NORMAL)
9899
.publicToAll(false)
99100
.publicToMarketplace(false)
@@ -118,7 +119,7 @@ public Mono<BundleInfoView> create(CreateBundleRequest createBundleRequest) {
118119
return bundleService.create(bundle);
119120
})
120121
.delayUntil(created -> autoGrantPermissionsByFolderDefault(created.getId(), createBundleRequest.folderId()))
121-
.delayUntil(created -> folderApiService.move(created.getId(),
122+
.delayUntil(created -> folderApiService.moveBundle(created.getId(),
122123
createBundleRequest.folderId()))
123124
.flatMap(f -> buildBundleInfoView(f, true, true, createBundleRequest.folderId()));
124125
}
@@ -587,6 +588,7 @@ public Mono<BundleInfoView> buildBundleInfoView(Bundle bundle, boolean visible,
587588
.map(user -> BundleInfoView.builder()
588589
.userId(bundle.getCreatedBy())
589590
.bundleId(bundle.getId())
591+
.title(bundle.getTitle())
590592
.name(bundle.getName())
591593
.description(bundle.getDescription())
592594
.category(bundle.getCategory())

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/home/FolderApiService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public interface FolderApiService {
2323
Mono<FolderInfoView> update(Folder folder);
2424

2525
Mono<Void> move(String applicationLikeId, @Nullable String targetFolderId);
26+
Mono<Void> moveBundle(String bundleId, @Nullable String targetFolderId);
2627

2728
Mono<Void> upsertLastViewTime(@Nullable String folderId);
2829

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/home/FolderApiServiceImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ public Mono<Void> move(String applicationLikeId, @Nullable String targetFolderId
196196
.then();
197197
}
198198

199+
/**
200+
* @param targetFolderId null means root folder
201+
*/
202+
@Override
203+
public Mono<Void> moveBundle(String bundleId, @Nullable String targetFolderId) {
204+
return sessionUserService.getVisitorId()
205+
// check permissions
206+
.delayUntil(userId -> resourcePermissionService.checkResourcePermissionWithError(userId, bundleId,
207+
ResourceAction.MANAGE_BUNDLES))
208+
// remove old relations
209+
.then(folderElementRelationService.deleteByElementId(bundleId))
210+
.flatMap(b -> {
211+
if (StringUtils.isBlank(targetFolderId)) {
212+
return Mono.empty();
213+
}
214+
return folderElementRelationService.create(targetFolderId, bundleId);
215+
})
216+
.then();
217+
}
218+
199219
@Override
200220
public Mono<Void> upsertLastViewTime(@Nullable String folderId) {
201221
if (StringUtils.isBlank(folderId)) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.lowcoder.api.bundle;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.lowcoder.api.bundle.view.BundleInfoView;
6+
import org.lowcoder.api.home.SessionUserServiceImpl;
7+
import org.lowcoder.domain.organization.model.MemberRole;
8+
import org.lowcoder.domain.organization.model.OrgMember;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.boot.test.mock.mockito.MockBean;
12+
import org.springframework.test.context.junit4.SpringRunner;
13+
import reactor.core.publisher.Mono;
14+
import reactor.test.StepVerifier;
15+
16+
import static org.junit.jupiter.api.Assertions.*;
17+
import static org.mockito.Mockito.when;
18+
19+
@SpringBootTest
20+
@RunWith(SpringRunner.class)
21+
public class BundleApiServiceImplTest {
22+
@Autowired
23+
BundleApiServiceImpl bundleApiService;
24+
@MockBean
25+
SessionUserServiceImpl sessionUserService;
26+
27+
@Test
28+
public void createBundleTest() {
29+
when(sessionUserService.getVisitorId()).thenReturn(Mono.just("user01"));
30+
when(sessionUserService.getVisitorOrgMemberCache()).thenReturn(Mono.just(new OrgMember("org01", "user01", MemberRole.ADMIN, "NORMAL", 0)));
31+
Mono<BundleInfoView> bundleInfoViewMono = bundleApiService.create(new BundleEndpoints.CreateBundleRequest(
32+
"org01",
33+
"name",
34+
"title",
35+
"description",
36+
"category",
37+
"image",
38+
null));
39+
StepVerifier.create(bundleInfoViewMono)
40+
.assertNext(bundleInfoView -> {
41+
assertNotNull(bundleInfoView.getBundleId());
42+
assertEquals("name", bundleInfoView.getName());
43+
assertEquals("title", bundleInfoView.getTitle());
44+
assertEquals("description", bundleInfoView.getDescription());
45+
assertEquals("category", bundleInfoView.getCategory());
46+
assertEquals("image", bundleInfoView.getImage());
47+
assertFalse(bundleInfoView.getPublicToAll());
48+
assertFalse(bundleInfoView.getPublicToMarketplace());
49+
assertFalse(bundleInfoView.getAgencyProfile());
50+
assertNull(bundleInfoView.getFolderId());
51+
})
52+
.verifyComplete();
53+
}
54+
}

0 commit comments

Comments
 (0)