ソースを参照

Feature: Expose the refreshToken method

Expose the refreshToken method.
Bartosz Czerwonka 5 年 前
コミット
d3154d28d1

+ 5 - 6
packages/ckeditor-cloud-services-core/src/token/token.js

@@ -89,7 +89,7 @@ class Token {
 			}
 
 			if ( !this.value ) {
-				this._refreshToken()
+				this.refreshToken()
 					.then( resolve )
 					.catch( reject );
 
@@ -102,10 +102,9 @@ class Token {
 
 	/**
 	 * Refresh token method. Useful in a method form as it can be override in tests.
-	 *
-	 * @protected
+	 * @returns {Promise.<String>}
 	 */
-	_refreshToken() {
+	refreshToken() {
 		return this._refresh()
 			.then( value => this.set( 'value', value ) )
 			.then( () => this );
@@ -124,7 +123,7 @@ class Token {
 	 * @protected
 	 */
 	_startRefreshing() {
-		this._refreshInterval = setInterval( () => this._refreshToken(), this._options.refreshInterval );
+		this._refreshInterval = setInterval( () => this.refreshToken(), this._options.refreshInterval );
 	}
 
 	/**
@@ -157,7 +156,7 @@ class Token {
 mix( Token, ObservableMixin );
 
 /**
- * This function is called in a defined interval by the {@link ~Token} class.
+ * This function is called in a defined interval by the {@link ~Token} class. It also can be invoked manually.
  * It should return a promise, which resolves with the new token value.
  * If any error occurs it should return a rejected promise with an error message.
  *

+ 4 - 4
packages/ckeditor-cloud-services-core/tests/token/token.js

@@ -129,11 +129,11 @@ describe( 'Token', () => {
 		} );
 	} );
 
-	describe( '_refreshToken()', () => {
+	describe( 'refreshToken()', () => {
 		it( 'should get a token from the specified address', done => {
 			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
-			token._refreshToken()
+			token.refreshToken()
 				.then( newToken => {
 					expect( newToken.value ).to.equal( 'token-value' );
 
@@ -146,7 +146,7 @@ describe( 'Token', () => {
 		it( 'should get a token from the specified callback function', () => {
 			const token = new Token( () => Promise.resolve( 'token-value' ), { initValue: 'initValue', autoRefresh: false } );
 
-			return token._refreshToken()
+			return token.refreshToken()
 				.then( newToken => {
 					expect( newToken.value ).to.equal( 'token-value' );
 				} );
@@ -195,7 +195,7 @@ describe( 'Token', () => {
 		it( 'should throw an error when the callback throws error', () => {
 			const token = new Token( () => Promise.reject( 'Custom error occurred' ), { initValue: 'initValue', autoRefresh: false } );
 
-			token._refreshToken()
+			token.refreshToken()
 				.catch( error => {
 					expect( error ).to.equal( 'Custom error occurred' );
 				} );