Skip to content
Open
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 @@ -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']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
55 changes: 55 additions & 0 deletions src/app/features/registries/services/registries.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
}
);
});
6 changes: 5 additions & 1 deletion src/app/features/registries/services/registries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ export class RegistriesService {
createDraft(
registrationSchemaId: string,
provider: string,
projectId?: string | undefined
acceptableUseConfirmed: boolean,
projectId?: string
): Observable<DraftRegistrationModel> {
const payload = {
data: {
type: 'draft_registrations',
attributes: {
acceptable_use_confirmed: acceptableUseConfirmed,
},
relationships: {
branched_from: projectId
? {
Expand Down
9 changes: 8 additions & 1 deletion src/app/features/registries/store/registries.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/app/features/registries/store/registries.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ export class RegistriesState {

@Action(CreateDraft)
createDraft(ctx: StateContext<RegistriesStateModel>, { payload }: CreateDraft) {
const { registrationSchemaId, provider, acceptableUseConfirmed, projectId } = payload;

ctx.patchState({
draftRegistration: {
...ctx.getState().draftRegistration,
isSubmitting: true,
},
});

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: {
Expand Down
Loading