diff --git a/src/app/onboarding/components/create-new-archive/create-new-archive.component.spec.ts b/src/app/onboarding/components/create-new-archive/create-new-archive.component.spec.ts index cefa2ec9d..365e66444 100644 --- a/src/app/onboarding/components/create-new-archive/create-new-archive.component.spec.ts +++ b/src/app/onboarding/components/create-new-archive/create-new-archive.component.spec.ts @@ -7,11 +7,15 @@ import { ApiService } from '@shared/services/api/api.service'; import { AccountService } from '@shared/services/account/account.service'; import { AccountVO } from '@models/account-vo'; import { EventService } from '@shared/services/event/event.service'; +import { FeatureFlagService } from '@root/app/feature-flag/services/feature-flag.service'; +import { SecretsService } from '@shared/services/secrets/secrets.service'; import { OnboardingService } from '../../services/onboarding.service'; import { CreateNewArchiveComponent } from './create-new-archive.component'; +let calledAccept: boolean = false; let calledCreate: boolean = false; let createdArchive: ArchiveVO | null; +let acceptedArchive: ArchiveVO | undefined; const mockApiService = { archive: { create: async (a: ArchiveVO) => { @@ -21,6 +25,13 @@ const mockApiService = { getArchiveVO: () => a, }; }, + accept: async (a: ArchiveVO) => { + calledAccept = true; + acceptedArchive = a; + return { + getArchiveVO: () => a, + }; + }, }, }; @@ -53,15 +64,21 @@ function enterText(selector: string, text: string, find: any): void { } describe('CreateNewArchiveComponent #onboarding', () => { + let feature: FeatureFlagService; beforeEach(() => { + feature = new FeatureFlagService(undefined, new SecretsService()); calledCreate = false; createdArchive = null; + calledAccept = false; + acceptedArchive = null; shallow = new Shallow(CreateNewArchiveComponent, OnboardingModule) .mock(ApiService, mockApiService) .mock(AccountService, mockAccountService) .provide(EventService) + .provide({ provide: FeatureFlagService, useValue: feature }) .dontMock(EventService) - .dontMock(OnboardingService); + .dontMock(OnboardingService) + .dontMock(FeatureFlagService); }); it('should exist', async () => { @@ -127,4 +144,24 @@ describe('CreateNewArchiveComponent #onboarding', () => { expect(submitButton.disabled).toBe(true); expect(skipStepButton.disabled).toBe(true); }); + + it('should accept pending archives in the old flow', async () => { + feature.set('glam-onboarding', false); + const { instance } = await shallow.render(); + instance.pendingArchive = new ArchiveVO({ archiveId: 1234 }); + await instance.onSubmit(); + + expect(calledAccept).toBeTrue(); + expect(acceptedArchive.archiveId).toBe(1234); + }); + + it('should not accept pending archives in the glam flow (they are already accepted in an earlier step)', async () => { + feature.set('glam-onboarding', true); + const { instance } = await shallow.render(); + instance.pendingArchive = new ArchiveVO({ archiveId: 1234 }); + await instance.onSubmit(); + + expect(calledAccept).toBeFalse(); + expect(acceptedArchive).toBeNull(); + }); }); diff --git a/src/app/onboarding/components/create-new-archive/create-new-archive.component.ts b/src/app/onboarding/components/create-new-archive/create-new-archive.component.ts index aa58d5500..9bc6235bf 100644 --- a/src/app/onboarding/components/create-new-archive/create-new-archive.component.ts +++ b/src/app/onboarding/components/create-new-archive/create-new-archive.component.ts @@ -210,7 +210,9 @@ export class CreateNewArchiveComponent implements OnInit { let response; if (this.pendingArchive) { - await this.api.archive.accept(this.pendingArchive); + if (!this.isGlam) { + await this.api.archive.accept(this.pendingArchive); + } } else { response = await this.api.archive.create(archive); createdArchive = response.getArchiveVO();