Skip to content

Commit 5216b20

Browse files
May HartovMay Hartov
authored andcommitted
Merged PR 4587: initialized local accessToken fields on setAccessToken post success
initialized local accessToken fields on setAccessToken post success
1 parent 7f5ace6 commit 5216b20

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/embed.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,16 @@ export abstract class Embed {
382382
var embedType = this.config.type;
383383
return this.service.hpm.post<models.IError[]>('/' + embedType + '/token', accessToken, { uid: this.config.uniqueId }, this.iframe.contentWindow)
384384
.then(response => {
385+
this.config.accessToken = accessToken;
386+
this.element.setAttribute(Embed.accessTokenAttribute, accessToken);
387+
this.service.accessToken = accessToken;
385388
return response.body;
386389
})
387390
.catch(response => {
388391
throw response.body;
389392
});
390393
}
391-
394+
392395
/**
393396
* Gets an access token from the first available location: config, attribute, global.
394397
*

test/test.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,11 +3102,15 @@ describe('SDK-to-HPM', function () {
31023102
body: {}
31033103
}));
31043104

3105+
let newToken = "newToken"
31053106
// Act
3106-
report.setAccessToken(accessToken)
3107+
report.setAccessToken(newToken)
31073108
.then(() => {
31083109
// Assert
3109-
expect(spyHpm.post).toHaveBeenCalledWith('/report/token', accessToken, { uid: uniqueId }, iframe.contentWindow);
3110+
expect(spyHpm.post).toHaveBeenCalledWith('/report/token', newToken, { uid: uniqueId }, iframe.contentWindow);
3111+
expect(report.service.accessToken).toEqual(newToken);
3112+
expect(report.config.accessToken).toEqual(newToken);
3113+
expect(report.element.getAttribute(embed.Embed.accessTokenAttribute)).toEqual(newToken);
31103114
done();
31113115
});
31123116
});

0 commit comments

Comments
 (0)