把可拼装的排到前面,再根据发布时间排序
This commit is contained in:
@@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
import com.linkerbot.vibemake.common.ProjectListingFixtures;
|
||||
import com.linkerbot.vibemake.security.CaptchaService;
|
||||
import com.linkerbot.vibemake.service.admin.AdminProjectResourceService;
|
||||
import com.linkerbot.vibemake.service.support.ProjectActors;
|
||||
@@ -205,6 +206,68 @@ class WorkflowTest {
|
||||
200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void communitySortsCompleteResourcesBeforePublicationTimeAndPaginatesStably() throws Exception {
|
||||
String owner = login("project-sorting@example.invalid");
|
||||
String template = create(owner, "列表模板");
|
||||
ProjectListingFixtures.Fixture fixture = ProjectListingFixtures.create(jdbc.getDataSource(), template);
|
||||
jdbc.update("UPDATE project SET deleted=1 WHERE project_code=?", template);
|
||||
String urdfOnly = fixture.resourcesOrder().getLast();
|
||||
jdbc.update("UPDATE project SET urdf_main_object_key=? WHERE project_code=?",
|
||||
"/urdf/" + urdfOnly + "/robot.urdf", urdfOnly);
|
||||
List<String> actual = new ArrayList<>();
|
||||
for (int page = 1; page <= 4; page++) {
|
||||
JsonNode data = perform(get("/api/community/projects")
|
||||
.param("page", Integer.toString(page)).param("size", "3")
|
||||
.param("type", "GENERAL").param("keyword", "排序测试"), 200).path("data");
|
||||
assertThat(data.path("total").asLong()).isEqualTo(10);
|
||||
for (JsonNode project : data.path("items")) {
|
||||
assertThat(project.has("id")).isFalse();
|
||||
actual.add(project.path("projectCode").asText());
|
||||
}
|
||||
}
|
||||
assertThat(actual).containsExactlyElementsOf(fixture.resourcesOrder());
|
||||
JsonNode workspace = perform(auth(get("/api/workspace/projects"), owner)
|
||||
.param("size", "20"), 200).path("data");
|
||||
assertThat(workspace.path("items")).extracting(p -> p.path("projectCode").asText())
|
||||
.containsExactlyElementsOf(fixture.createdOrder());
|
||||
assertThat(perform(get("/api/community/projects").param("type", "ROBOTIC_ARM"), 200)
|
||||
.path("data").path("total").asLong()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void workspaceCannotEditPublicationTimeAndRepublishingKeepsExistingTime() throws Exception {
|
||||
String owner = login("publication-time@example.invalid");
|
||||
String code = create(owner, "发布时间测试");
|
||||
String endpoint = "/api/workspace/projects/" + code;
|
||||
String sha = head(owner, code);
|
||||
assertThat(perform(auth(get(endpoint), owner), 200).path("data").path("publishedAt").isNull())
|
||||
.isTrue();
|
||||
publish(owner, code, sha);
|
||||
assertThat(perform(auth(get(endpoint), owner), 200).path("data").path("publishedAt").isTextual())
|
||||
.isTrue();
|
||||
String manualTime = "2020-01-02T03:04:05.123";
|
||||
jdbc.update("UPDATE project SET published_at=? WHERE project_code=?", manualTime, code);
|
||||
Map<String, Object> input = new HashMap<>(Map.of(
|
||||
"name", "发布时间测试", "projectType", "GENERAL", "description", "普通用户编辑"));
|
||||
input.put("publishedAt", "2030-01-01T00:00:00");
|
||||
input.put("publishedAtProvided", true);
|
||||
JsonNode updated = perform(body(auth(patch(endpoint), owner), input), 200).path("data");
|
||||
assertThat(updated.path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
input.put("publishedAt", null);
|
||||
perform(body(auth(patch(endpoint), owner), input), 200);
|
||||
String nextSha = commit(owner, code, sha, "再次发布测试");
|
||||
publish(owner, code, nextSha);
|
||||
JsonNode republished = perform(auth(get(endpoint), owner), 200).path("data");
|
||||
assertThat(republished.path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
assertThat(republished.path("publishedCommitSha").asText()).isEqualTo(nextSha);
|
||||
jdbc.update("UPDATE project SET published_at=NULL WHERE project_code=?", code);
|
||||
publish(owner, code, nextSha);
|
||||
JsonNode filledTime = perform(auth(get(endpoint), owner), 200).path("data").path("publishedAt");
|
||||
assertThat(filledTime.isTextual()).isTrue();
|
||||
assertThat(filledTime.asText()).isNotEqualTo(manualTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
void crossOriginLoginDownloadsAndBusinessErrorsKeepCorsHeaders() throws Exception {
|
||||
String origin = "https://dev-vibemake.robotquan.com";
|
||||
|
||||
Reference in New Issue
Block a user