fix(tests): address test failures in PR #493

Backend test fixes:
- Remove unnecessary Mockito stubbing for filtered-out skills
- Add missing findBySkillIdAndStatus stub for published version lookup
- Update MeController test mocks to match new method signature (keyword, namespace params)

Frontend fixes:
- Fix TypeScript error: useMyNamespaces returns ManagedNamespace[] not PagedResponse
- Add type annotation for namespace map callback parameter

E2E test fix:
- Update URL regex to allow query parameters (returnTo from search page)

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
XiaoSeS 2026-06-05 16:46:05 +08:00
parent 2fc200a00b
commit 0f74b8f7fa
4 changed files with 7 additions and 9 deletions

View file

@ -56,7 +56,7 @@ class MeControllerTest {
principal, null, List.of(new SimpleGrantedAuthority("ROLE_USER"))
);
given(mySkillAppService.listMySkills("user-42", 1, 5, null, Set.of("USER")))
given(mySkillAppService.listMySkills("user-42", 1, 5, null, null, null, Set.of("USER")))
.willReturn(new PageResponse<>(
List.of(new SkillSummaryResponse(
7L,
@ -103,7 +103,7 @@ class MeControllerTest {
principal, null, List.of(new SimpleGrantedAuthority("ROLE_SUPER_ADMIN"))
);
given(mySkillAppService.listMySkills("user-42", 0, 10, "HIDDEN", Set.of("SUPER_ADMIN")))
given(mySkillAppService.listMySkills("user-42", 0, 10, "HIDDEN", null, null, Set.of("SUPER_ADMIN")))
.willReturn(new PageResponse<>(List.of(), 0, 0, 10));
mockMvc.perform(get("/api/v1/me/skills")

View file

@ -274,6 +274,7 @@ class MySkillAppServiceTest {
given(skillRepository.findByOwnerId("user-1", PageRequest.of(0, 10)))
.willReturn(new PageImpl<>(List.of(skill), PageRequest.of(0, 10), 1));
given(skillVersionRepository.findBySkillIdAndStatus(6L, SkillVersionStatus.PUBLISHED)).willReturn(List.of(publishedVersion));
given(skillVersionRepository.findBySkillId(6L)).willReturn(List.of(rejectedVersion, publishedVersion));
given(namespaceRepository.findByIdIn(List.of(101L))).willReturn(List.of(namespace(101L, "team-ai")));
@ -299,7 +300,6 @@ class MySkillAppServiceTest {
given(skillRepository.findByOwnerId("user-1")).willReturn(List.of(alpha, beta, gamma));
given(skillVersionRepository.findBySkillId(1L)).willReturn(List.of(publishedVersion));
given(skillVersionRepository.findBySkillId(2L)).willReturn(List.of());
given(skillVersionRepository.findBySkillId(3L)).willReturn(List.of());
given(namespaceRepository.findByIdIn(List.of(101L))).willReturn(List.of(namespace(101L, "team-ai")));
var result = service.listMySkills("user-1", 0, 10, null, "alpha", null, Set.of("USER"));
@ -314,11 +314,9 @@ class MySkillAppServiceTest {
Skill aiSkill = createSkill(1L, 101L, "ai-tool", "user-1");
Skill mlSkill = createSkill(2L, 102L, "ml-tool", "user-1");
SkillVersion v1 = createVersion(1L, 10L, "1.0.0", SkillVersionStatus.PUBLISHED, "2026-03-15T09:30:00Z");
SkillVersion v2 = createVersion(2L, 20L, "1.0.0", SkillVersionStatus.PUBLISHED, "2026-03-15T09:30:00Z");
given(skillRepository.findByOwnerId("user-1")).willReturn(List.of(aiSkill, mlSkill));
given(skillVersionRepository.findBySkillId(1L)).willReturn(List.of(v1));
given(skillVersionRepository.findBySkillId(2L)).willReturn(List.of(v2));
given(namespaceRepository.findBySlug("team-ai")).willReturn(java.util.Optional.of(namespace(101L, "team-ai")));
given(namespaceRepository.findByIdIn(List.of(101L))).willReturn(List.of(namespace(101L, "team-ai")));
@ -354,6 +352,7 @@ class MySkillAppServiceTest {
SkillVersion v3 = createVersion(3L, 30L, "1.0.0", SkillVersionStatus.PUBLISHED, "2026-03-15T09:30:00Z");
given(skillRepository.findByOwnerId("user-1")).willReturn(List.of(aiAlpha, aiBeta, mlAlpha));
given(skillVersionRepository.findBySkillIdAndStatus(1L, SkillVersionStatus.PUBLISHED)).willReturn(List.of(v1));
given(skillVersionRepository.findBySkillId(1L)).willReturn(List.of(v1));
given(skillVersionRepository.findBySkillId(2L)).willReturn(List.of(v2));
given(skillVersionRepository.findBySkillId(3L)).willReturn(List.of(v3));

View file

@ -36,7 +36,7 @@ test.describe('Public Skill Detail Anonymous Access (Real API)', () => {
await card.click()
await expect(page).toHaveURL(new RegExp(`/space/${current.skill.namespace}/${current.skill.slug}$`))
await expect(page).toHaveURL(new RegExp(`/space/${current.skill.namespace}/${current.skill.slug}(\\?|$)`))
await expect(page).not.toHaveURL(/\/login\?returnTo=/)
await expect(page.getByRole('heading', { name: current.skillName, exact: true })).toBeVisible()
await expect(page.getByText('Install', { exact: true })).toBeVisible()

View file

@ -91,8 +91,7 @@ export function MySkillsPage() {
q: keyword || undefined,
namespace: namespaceFilter || undefined,
})
const { data: namespacesPage } = useMyNamespaces({ page: 0, size: 100 })
const namespaceOptions = namespacesPage?.items ?? []
const { data: namespaceOptions } = useMyNamespaces()
const skills = skillPage?.items ?? []
const totalPages = skillPage ? Math.max(Math.ceil(skillPage.total / skillPage.size), 1) : 1
@ -314,7 +313,7 @@ export function MySkillsPage() {
</SelectTrigger>
<SelectContent>
<SelectItem value={ALL_NAMESPACES_VALUE}>{t('mySkills.namespaceFilterAll')}</SelectItem>
{namespaceOptions.map((ns) => (
{(namespaceOptions ?? []).map((ns: { id: number; slug: string }) => (
<SelectItem key={ns.id} value={ns.slug}>
@{ns.slug}
</SelectItem>