浏览代码

Docs: Added a few notes to docs

Bartosz Czerwonka 8 年之前
父节点
当前提交
9e1215d1b6

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

@@ -21,10 +21,11 @@ const DEFAULT_OPTIONS = { refreshInterval: 3600000, autoRefresh: true };
 class Token {
 	/**
 	 * Creates `Token` instance.
+	 * Method `init` should be called after using the constructor or use `create` method instead.
 	 *
 	 * @param {String} tokenUrl Endpoint address to download the token.
 	 * @param {Object} options
-	 * @param {String} [options.initTokenValue] Initial value of the token.
+	 * @param {String} [options.initValue] Initial value of the token.
 	 * @param {Number} [options.refreshInterval=3600000] Delay between refreshes. Default 1 hour.
 	 * @param {Boolean} [options.autoRefresh=true] Specifies whether to start the refresh automatically.
 	 */
@@ -35,6 +36,8 @@ class Token {
 
 		/**
 		 * Value of the token.
+		 * The value of the token is null if `initValue` is not provided or `init` method was not called.
+		 * `create` method creates token with initialized value from url.
 		 *
 		 * @name value
 		 * @type {String}
@@ -42,7 +45,7 @@ class Token {
 		 * @readonly
 		 * @memberOf Token#
 		 */
-		this.set( 'value', options.initTokenValue );
+		this.set( 'value', options.initValue );
 
 		/**
 		 * @type {String}
@@ -135,7 +138,7 @@ class Token {
 	 *
 	 * @param {String} tokenUrl Endpoint address to download the token.
 	 * @param {Object} options
-	 * @param {String} [options.initTokenValue] Initial value of the token.
+	 * @param {String} [options.initValue] Initial value of the token.
 	 * @param {Number} [options.refreshInterval=3600000] Delay between refreshes. Default 1 hour.
 	 * @param {Boolean} [options.autoRefresh=true] Specifies whether to start the refresh automatically.
 	 * @returns {Promise.<Token>}

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

@@ -30,7 +30,7 @@ describe( 'Token', () => {
 		} );
 
 		it( 'should set a init token value', () => {
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			expect( token.value ).to.equal( 'initValue' );
 		} );
@@ -67,7 +67,7 @@ describe( 'Token', () => {
 		it( 'should start token refresh every 1 hour', done => {
 			const clock = sinon.useFakeTimers( { toFake: [ 'setInterval' ] } );
 
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue' } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue' } );
 
 			token.init()
 				.then( () => {
@@ -88,7 +88,7 @@ describe( 'Token', () => {
 
 	describe( '_refreshToken()', () => {
 		it( 'should get a token from the specified address', done => {
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			token._refreshToken()
 				.then( newToken => {
@@ -101,7 +101,7 @@ describe( 'Token', () => {
 		} );
 
 		it( 'should throw error when cannot download new token ', done => {
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			token._refreshToken()
 				.catch( error => {
@@ -114,7 +114,7 @@ describe( 'Token', () => {
 		} );
 
 		it( 'should throw error when response is aborted', done => {
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			token._refreshToken()
 				.catch( error => {
@@ -127,7 +127,7 @@ describe( 'Token', () => {
 		} );
 
 		it( 'should throw error event when network error occurs', done => {
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			token._refreshToken()
 				.catch( error => {
@@ -144,7 +144,7 @@ describe( 'Token', () => {
 		it( 'should start refreshing', () => {
 			const clock = sinon.useFakeTimers( { toFake: [ 'setInterval' ] } );
 
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue', autoRefresh: false } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue', autoRefresh: false } );
 
 			token._startRefreshing();
 
@@ -164,7 +164,7 @@ describe( 'Token', () => {
 		it( 'should stop refreshing', done => {
 			const clock = sinon.useFakeTimers( { toFake: [ 'setInterval', 'clearInterval' ] } );
 
-			const token = new Token( 'http://token-endpoint', { initTokenValue: 'initValue' } );
+			const token = new Token( 'http://token-endpoint', { initValue: 'initValue' } );
 
 			token.init()
 				.then( () => {

+ 1 - 1
packages/ckeditor-cloud-services-core/tests/uploadgateway/fileuploader.js

@@ -15,7 +15,7 @@ const BASE_64_FILE = 'data:image/gif;base64,R0lGODlhCQAJAPIAAGFhYZXK/1FRUf///' +
 	'9ra2gD/AAAAAAAAACH5BAEAAAUALAAAAAAJAAkAAAMYWFqwru2xERcYJLSNNWNBVimC5wjfaTkJADs=';
 
 describe( 'FileUploader', () => {
-	const token = new Token( 'url', { initTokenValue: 'token', autoRefresh: false } );
+	const token = new Token( 'url', { initValue: 'token', autoRefresh: false } );
 
 	let fileUploader;
 

+ 1 - 1
packages/ckeditor-cloud-services-core/tests/uploadgateway/uploadgateway.js

@@ -10,7 +10,7 @@ import UploadGateway from '../../src/uploadgateway/uploadgateway';
 import Token from '../../src/token/token';
 
 describe( 'UploadGateway', () => {
-	const token = new Token( 'url', { initTokenValue: 'token', autoRefresh: false } );
+	const token = new Token( 'url', { initValue: 'token', autoRefresh: false } );
 
 	describe( 'constructor()', () => {
 		it( 'should throw error when no token provided', () => {