Skip to content

Commit dd69f15

Browse files
committed
Create account from restricted share link completes share
When a user is accessing a restricted share link without an account, a create account modal will appear. After the user follows the whole onboarding flow, when he navigates to shares, he will see the accepted share. ISSUE: PER-10446
1 parent fcb0e7b commit dd69f15

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/app/onboarding/components/create-new-archive/create-new-archive.component.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const mockApiService = {
2626
};
2727
},
2828
},
29+
share: {
30+
requestShareAccess: jasmine.createSpy('requestShareAccess').and.resolveTo(),
31+
},
2932
};
3033

3134
const mockAccountService = {
@@ -45,6 +48,7 @@ describe('CreateNewArchiveComponent #onboarding', () => {
4548
feature = new FeatureFlagService(undefined, new SecretsService());
4649
calledAccept = false;
4750
acceptedArchive = null;
51+
mockApiService.share.requestShareAccess.calls.reset();
4852

4953
await TestBed.configureTestingModule({
5054
declarations: [CreateNewArchiveComponent],
@@ -146,4 +150,52 @@ describe('CreateNewArchiveComponent #onboarding', () => {
146150
expect(calledAccept).toBeFalse();
147151
expect(acceptedArchive).toBeNull();
148152
});
153+
154+
it('should call requestShareAccess with shareToken from localStorage', async () => {
155+
spyOn(localStorage, 'getItem').and.callFake((key: string) => {
156+
if (key === 'shareToken') return 'test-share-token';
157+
return null;
158+
});
159+
160+
await component.onSubmit();
161+
162+
expect(mockApiService.share.requestShareAccess).toHaveBeenCalledWith(
163+
'test-share-token',
164+
);
165+
});
166+
167+
it('should call requestShareAccess with shareTokenFromCopy when shareToken is not present', async () => {
168+
spyOn(localStorage, 'getItem').and.callFake((key: string) => {
169+
if (key === 'shareTokenFromCopy') return 'test-share-token-from-copy';
170+
return null;
171+
});
172+
173+
await component.onSubmit();
174+
175+
expect(mockApiService.share.requestShareAccess).toHaveBeenCalledWith(
176+
'test-share-token-from-copy',
177+
);
178+
});
179+
180+
it('should prefer shareToken over shareTokenFromCopy when both are present', async () => {
181+
spyOn(localStorage, 'getItem').and.callFake((key: string) => {
182+
if (key === 'shareToken') return 'primary-token';
183+
if (key === 'shareTokenFromCopy') return 'secondary-token';
184+
return null;
185+
});
186+
187+
await component.onSubmit();
188+
189+
expect(mockApiService.share.requestShareAccess).toHaveBeenCalledWith(
190+
'primary-token',
191+
);
192+
});
193+
194+
it('should not call requestShareAccess when no share token exists in localStorage', async () => {
195+
spyOn(localStorage, 'getItem').and.returnValue(null);
196+
197+
await component.onSubmit();
198+
199+
expect(mockApiService.share.requestShareAccess).not.toHaveBeenCalled();
200+
});
149201
});

src/app/onboarding/components/create-new-archive/create-new-archive.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ export class CreateNewArchiveComponent implements OnInit {
205205
response = await this.api.archive.create(archive);
206206
createdArchive = response.getArchiveVO();
207207
}
208+
209+
const shareToken =
210+
localStorage.getItem('shareToken') ||
211+
localStorage.getItem('shareTokenFromCopy');
212+
if (shareToken) {
213+
await this.api.share.requestShareAccess(shareToken);
214+
}
208215
} catch (archiveError) {
209216
this.errorOccurred.emit('An error occurred. Please try again.');
210217
}

0 commit comments

Comments
 (0)