From 2404171037f69c01581489d111b85ff0a464692c Mon Sep 17 00:00:00 2001 From: Oleh-Sali Date: Fri, 27 Nov 2026 14:17:36 +0000 Subject: [PATCH] fix(registries): send acceptable use confirmation when creating a draft --- .../new-registration.component.spec.ts | 7 ++- .../new-registration.component.ts | 1 + .../services/registries.service.spec.ts | 55 +++++++++++++++++++ .../registries/services/registries.service.ts | 6 +- .../registries/store/registries.actions.ts | 9 ++- .../registries/store/registries.state.ts | 4 +- 6 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/app/features/registries/services/registries.service.spec.ts diff --git a/src/app/features/registries/components/new-registration/new-registration.component.spec.ts b/src/app/features/registries/components/new-registration/new-registration.component.spec.ts index a6a5b5e3d..aee915f17 100644 --- a/src/app/features/registries/components/new-registration/new-registration.component.spec.ts +++ b/src/app/features/registries/components/new-registration/new-registration.component.spec.ts @@ -170,7 +170,12 @@ describe('NewRegistrationComponent', () => { expect(component.isCreateDraftDisabled()).toBe(false); expect(store.dispatch).toHaveBeenCalledWith( - new CreateDraft({ registrationSchemaId: 'schema-1', provider: 'prov-1', projectId: 'proj-1' }) + new CreateDraft({ + registrationSchemaId: 'schema-1', + provider: 'prov-1', + acceptableUseConfirmed: true, + projectId: 'proj-1', + }) ); expect(mockRouter.navigate).toHaveBeenCalledWith(['/registries/drafts/', 'draft-1', 'metadata']); }); diff --git a/src/app/features/registries/components/new-registration/new-registration.component.ts b/src/app/features/registries/components/new-registration/new-registration.component.ts index 6b1d8e66c..cd4cb3e05 100644 --- a/src/app/features/registries/components/new-registration/new-registration.component.ts +++ b/src/app/features/registries/components/new-registration/new-registration.component.ts @@ -111,6 +111,7 @@ export class NewRegistrationComponent { .createDraft({ registrationSchemaId: providerSchema!, provider: this.providerId, + acceptableUseConfirmed: this.policyAcknowledged(), projectId: this.fromProject() ? (project ?? undefined) : undefined, }) .pipe(takeUntilDestroyed(this.destroyRef)) diff --git a/src/app/features/registries/services/registries.service.spec.ts b/src/app/features/registries/services/registries.service.spec.ts new file mode 100644 index 000000000..740f81059 --- /dev/null +++ b/src/app/features/registries/services/registries.service.spec.ts @@ -0,0 +1,55 @@ +import { firstValueFrom } from 'rxjs'; + +import { HttpTestingController } from '@angular/common/http/testing'; +import { TestBed } from '@angular/core/testing'; + +import { provideOSFHttp } from '@testing/osf.testing.provider'; +import { MOCK_API_URL, provideMockEnvironment } from '@testing/providers/environment.provider.mock'; + +import { RegistriesService } from './registries.service'; + +describe('RegistriesService', () => { + let service: RegistriesService; + let httpMock: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [provideMockEnvironment(), provideOSFHttp()], + }); + service = TestBed.inject(RegistriesService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it.each([ + { provider: 'osf', schema: 'open-ended', projectId: undefined }, + { provider: 'branded-registry', schema: 'branded-template', projectId: 'project-1' }, + ])( + 'sends acceptable use confirmation when creating a draft for $provider', + async ({ provider, schema, projectId }) => { + const result = firstValueFrom(service.createDraft(schema, provider, true, projectId)); + const request = httpMock.expectOne({ method: 'POST', url: `${MOCK_API_URL}/draft_registrations/` }); + + expect(request.request.body).toEqual({ + data: { + type: 'draft_registrations', + attributes: { acceptable_use_confirmed: true }, + relationships: { + branched_from: projectId ? { data: { type: 'nodes', id: projectId } } : undefined, + registration_schema: { data: { type: 'registration-schemas', id: schema } }, + provider: { data: { type: 'registration-providers', id: provider } }, + }, + }, + }); + + request.flush( + { data: { id: 'draft-1', attributes: {}, relationships: {} } }, + { status: 201, statusText: 'Created' } + ); + expect((await result).id).toBe('draft-1'); + } + ); +}); diff --git a/src/app/features/registries/services/registries.service.ts b/src/app/features/registries/services/registries.service.ts index 3c275b86c..e49b6abeb 100644 --- a/src/app/features/registries/services/registries.service.ts +++ b/src/app/features/registries/services/registries.service.ts @@ -45,11 +45,15 @@ export class RegistriesService { createDraft( registrationSchemaId: string, provider: string, - projectId?: string | undefined + acceptableUseConfirmed: boolean, + projectId?: string ): Observable { const payload = { data: { type: 'draft_registrations', + attributes: { + acceptable_use_confirmed: acceptableUseConfirmed, + }, relationships: { branched_from: projectId ? { diff --git a/src/app/features/registries/store/registries.actions.ts b/src/app/features/registries/store/registries.actions.ts index 58c2c261a..f9a5ab4a4 100644 --- a/src/app/features/registries/store/registries.actions.ts +++ b/src/app/features/registries/store/registries.actions.ts @@ -29,7 +29,14 @@ export class GetProjects { export class CreateDraft { static readonly type = '[Registries] Create Draft'; - constructor(public payload: { registrationSchemaId: string; provider: string; projectId?: string }) {} + constructor( + public payload: { + registrationSchemaId: string; + provider: string; + acceptableUseConfirmed: boolean; + projectId?: string; + } + ) {} } export class FetchDraft { diff --git a/src/app/features/registries/store/registries.state.ts b/src/app/features/registries/store/registries.state.ts index 36c72356a..ec86e0e80 100644 --- a/src/app/features/registries/store/registries.state.ts +++ b/src/app/features/registries/store/registries.state.ts @@ -112,6 +112,8 @@ export class RegistriesState { @Action(CreateDraft) createDraft(ctx: StateContext, { payload }: CreateDraft) { + const { registrationSchemaId, provider, acceptableUseConfirmed, projectId } = payload; + ctx.patchState({ draftRegistration: { ...ctx.getState().draftRegistration, @@ -119,7 +121,7 @@ export class RegistriesState { }, }); - return this.registriesService.createDraft(payload.registrationSchemaId, payload.provider, payload.projectId).pipe( + return this.registriesService.createDraft(registrationSchemaId, provider, acceptableUseConfirmed, projectId).pipe( tap((registration) => { ctx.patchState({ draftRegistration: {