Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra call to archive/accept in Glam onboarding #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -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) => {
Expand All @@ -21,6 +25,13 @@ const mockApiService = {
getArchiveVO: () => a,
};
},
accept: async (a: ArchiveVO) => {
calledAccept = true;
acceptedArchive = a;
return {
getArchiveVO: () => a,
};
},
},
};

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading