Skip to content

Commit

Permalink
Merge pull request #7257 from ckeditor/i/7248
Browse files Browse the repository at this point in the history
Fix (cloud-services): Token instance will be destroyed by the CloudServices context plugin. Closes #7248.
  • Loading branch information
scofalik committed May 21, 2020
2 parents e3e9521 + d950542 commit 6b60cb6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/ckeditor5-cloud-services/src/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export default class CloudServices extends ContextPlugin {

return this.token.init();
}

/**
* @inheritDoc
*/
destroy() {
super.destroy();

if ( this.token ) {
this.token.destroy();
}
}
}

CloudServices.Token = Token;
Expand Down
31 changes: 31 additions & 0 deletions packages/ckeditor5-cloud-services/tests/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,35 @@ describe( 'CloudServices', () => {
} );
} );
} );

describe( 'destroy()', () => {
it( 'should destroy created token when tokenUrl was provided', async () => {
CloudServices.Token.initialToken = 'initial-token';

const context = await Context.create( {
plugins: [ CloudServices ],
cloudServices: {
tokenUrl: 'http://token-endpoint'
}
} );

const cloudServicesPlugin = context.plugins.get( CloudServices );

const destroySpy = sinon.spy( cloudServicesPlugin.token, 'destroy' );

await context.destroy();

sinon.assert.calledOnce( destroySpy );
} );

it( 'should not crash when tokenUrl was not provided', async () => {
const context = await Context.create( { plugins: [ CloudServices ] } );

try {
await context.destroy();
} catch ( error ) {
expect.fail( 'Error should not be thrown.' );
}
} );
} );
} );

0 comments on commit 6b60cb6

Please sign in to comment.