Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,17 @@ describe('appEventsService', () => {
data: expect.objectContaining({ args: payload }),
}))
})

// Garde de parité : zone.* est écouté par Vault mais émis uniquement par le legacy.
describe('emit surface (migration parity)', () => {
const expectedEmitMethods = ['emitProjectEvent', 'emitProjectMemberEvent', 'emitRepositoryEvent'] as const

it.each(expectedEmitMethods)('exposes %s as a public emit entrypoint', (method) => {
expect(typeof service[method]).toBe('function')
})

it('does NOT expose a zone emit entrypoint (zone.* listeners have no emitter yet — legacy owns the route)', () => {
expect('emitZoneEvent' in service).toBe(false)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DeepMockProxy } from 'vitest-mock-extended'
import type { AdminRoleWithDetails, ProjectWithDetails, UserWithAdminRoles } from './keycloak-datastore.service'
import { faker } from '@faker-js/faker'
import { Test } from '@nestjs/testing'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { mockDeep } from 'vitest-mock-extended'
Expand Down Expand Up @@ -526,4 +527,35 @@ describe('keycloakService', () => {
expect(keycloak.removeUserFromGroup).toHaveBeenCalledWith('user-2', 'system-managed-id')
})
})

describe('migration parity: admin-role event path (legacy hook.adminRole.*)', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[✨ Éloge] Les gardes négatives documentées (« pas d'emitAdminRoleEvent ») transforment un choix de migration en contrat testé — bon filet anti-régression pour le cutover.

const adminRoleId = faker.string.uuid()
const adminRoles: AdminRoleWithDetails[] = [
{ id: adminRoleId, name: faker.string.alphanumeric(8), permissions: 0n, position: 0, oidcGroup: '/admin-group', type: 'managed' },
]
const users: UserWithAdminRoles[] = [
{ id: faker.string.uuid(), adminRoleIds: [adminRoleId] },
]

it('syncs admin-role OIDC groups via cron reconcile ONLY (no event path exists)', async () => {
datastore.getAllProjects.mockResolvedValue([])
datastore.getAllAdminRoles.mockResolvedValue(adminRoles)
datastore.getAllUsersWithAdminRoleIds.mockResolvedValue(users)

const adminGroup = makeGroupRepresentation({ id: 'kc-parity-group-id', name: 'admin', path: '/console/parity-admin' })
keycloak.getOrCreateGroupByPath.mockResolvedValue(adminGroup)
keycloak.getGroupMembers.mockResolvedValue([])

await service.handleCron()

// Pas d'emit adminRole.* : la sync passe uniquement par le cron reconcile.
expect(keycloak.getOrCreateGroupByPath).toHaveBeenCalledWith('/admin-group')
})

it('exposes NO adminRole emit entrypoint on AppEventsService (cutover guard)', async () => {
const { AppEventsService } = await import('../events/app-events.service')
expect(Object.getOwnPropertyNames(AppEventsService.prototype))
.not.toContain('emitAdminRoleEvent')
})
})
})