XuqmGroup-Server/update-service/src/test/java/com/xuqm/update/controller/UpdateFileControllerTest.java

66 行
2.7 KiB
Java

package com.xuqm.update.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.xuqm.update.entity.RnBundleEntity;
import com.xuqm.update.repository.RnBundleRepository;
import com.xuqm.update.service.RnBundlePackageService;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class UpdateFileControllerTest {
@TempDir
Path tempDirectory;
@Test
void downloadRequiresExactRecordAppPlatformAndModuleIdentity() throws Exception {
RnBundleRepository repository = mock(RnBundleRepository.class);
RnBundlePackageService packageService = mock(RnBundlePackageService.class);
UpdateFileController controller = new UpdateFileController(repository, packageService);
RnBundleEntity entity = terminalEntity();
Path file = Files.writeString(tempDirectory.resolve("bundle.xuqm.zip"), "zip");
when(repository.findById("bundle-1")).thenReturn(Optional.of(entity));
when(packageService.verifyStoredFile(entity)).thenReturn(file);
assertThat(controller.downloadRnBundle(
"bundle-1", "ak_other", "android", "miniapp").getStatusCode().value())
.isEqualTo(404);
assertThat(controller.downloadRnBundle(
"bundle-1", "ak_app", "android", "miniapp").getStatusCode().value())
.isEqualTo(200);
verify(packageService).verifyStoredFile(entity);
}
private RnBundleEntity terminalEntity() {
RnBundleEntity entity = new RnBundleEntity();
entity.setId("bundle-1");
entity.setAppKey("ak_app");
entity.setPackageName("com.example");
entity.setModuleId("miniapp");
entity.setModuleType(RnBundleEntity.ModuleType.BUZ);
entity.setPlatform(RnBundleEntity.Platform.ANDROID);
entity.setVersion("1.0.0");
entity.setAppVersionRange(">=8.0.0 <9.0.0");
entity.setBuiltAgainstNativeBaselineId("android-sha256:base");
entity.setBuildId("build-1");
entity.setBundleFormat("hermes-bytecode");
entity.setCommonVersionRange(">=1.0.0 <2.0.0");
entity.setMinNativeApiLevel(2);
entity.setBundleSha256("a".repeat(64));
entity.setArchiveSha256("b".repeat(64));
entity.setBundleUrl("/tmp/bundle.zip");
entity.setSignedManifest("{}");
entity.setSigningKeyId("key");
entity.setSignature("signature");
entity.setPublishStatus(RnBundleEntity.PublishStatus.PUBLISHED);
return entity;
}
}