Skip to content
Merged
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
11 changes: 10 additions & 1 deletion sharedExample/src/ContentpassUsage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ export default function ContentpassUsage() {

spConsentManager.current?.onAction((action) => {
if (action.customActionId === "cp('login')") {
contentpassSdk.authenticate();
contentpassSdk
.authenticate()
.then(() => {
// eslint-disable-next-line no-console
console.log('Successfully authenticated');
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error('Failed to authenticate:', err);
});
}
});

Expand Down
17 changes: 10 additions & 7 deletions src/Contentpass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ describe('Contentpass', () => {
contentpassStates.push(state);
});

await contentpass.authenticate();
await expect(async () => {
await contentpass.authenticate();
}).rejects.toThrow(error);

expect(reportErrorSpy).toHaveBeenCalledWith(error, {
msg: 'Failed to authorize',
Expand Down Expand Up @@ -241,10 +243,10 @@ describe('Contentpass', () => {
).getTime();
const expectedDelay = expirationDate - NOW;

expect(refreshSpy).toBeCalledTimes(0);
expect(refreshSpy).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(expectedDelay);
expect(refreshSpy).toBeCalledTimes(1);
expect(refreshSpy).toBeCalledWith(
expect(refreshSpy).toHaveBeenCalledTimes(1);
expect(refreshSpy).toHaveBeenCalledWith(
{
clientId: 'propertyId-1',
redirectUrl: 'de.test.net://oauth',
Expand Down Expand Up @@ -274,7 +276,7 @@ describe('Contentpass', () => {

await contentpass.authenticate();

expect(refreshSpy).toBeCalledTimes(0);
expect(refreshSpy).toHaveBeenCalledTimes(0);

expect(contentpassStates).toHaveLength(2);
expect(contentpassStates[1]).toEqual({
Expand Down Expand Up @@ -414,8 +416,9 @@ describe('Contentpass', () => {
const error = new Error('Authorize error');
authorizeSpy.mockRejectedValue(error);

await contentpass.authenticate();

await expect(async () => {
await contentpass.authenticate();
}).rejects.toThrow(error);
expect(contentpassStates[1]).toEqual({
state: 'ERROR',
error,
Expand Down
4 changes: 2 additions & 2 deletions src/Contentpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ export default class Contentpass {
});
} catch (err: any) {
reportError(err, { msg: 'Failed to authorize' });

this.changeContentpassState({
state: ContentpassStateType.ERROR,
error: err,
});
return;

throw err;
}

await this.onNewAuthState(result);
Expand Down