ソースを参照

Removed error thrown when no token is provided.

Maciej Bukowski 8 年 前
コミット
9701f37d64

+ 10 - 15
packages/ckeditor5-cloud-services/src/cloudservices.js

@@ -9,7 +9,6 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Token from '@ckeditor/ckeditor-cloudservices-core/src/token/token';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Base plugin for Cloud Services. It takes care about the `cloudServices` config options and initializes token provider.
@@ -22,7 +21,7 @@ export default class CloudServices extends Plugin {
 		const editor = this.editor;
 		const config = editor.config;
 
-		const options = config.get( 'cloudServices' );
+		const options = config.get( 'cloudServices' ) || {};
 
 		for ( const optionName in options ) {
 			this[ optionName ] = options[ optionName ];
@@ -35,25 +34,21 @@ export default class CloudServices extends Plugin {
 		 * @member {String} #tokenUrl
 		 */
 
-		if ( !this.tokenUrl ) {
-			/**
-			 * The authentication `cloudServices.tokenUrl` config is not provided.
-			 *
-			 * @error cloudservices-token-endpoint-not-provided
-			 */
-			throw new CKEditorError(
-				'cloudservices-token-endpoint-not-provided: The authentication `cloudServices.tokenUrl` config is not provided.'
-			);
-		}
-
 		/**
 		 * Other plugins use this token for authorization process. It handles token requesting and refreshing.
+		 * Its value is null when `tokenUrl` is not provided.
 		 *
 		 * @readonly
+		 * @member {Object|null} #token
 		 */
-		this.token = new CloudServices.Token( this.tokenUrl );
 
-		return this.token.init();
+		if ( this.tokenUrl ) {
+			this.token = new CloudServices.Token( this.tokenUrl );
+
+			return this.token.init();
+		}
+
+		this.token = null;
 	}
 }
 

+ 15 - 8
packages/ckeditor5-cloud-services/tests/cloudservices.js

@@ -26,7 +26,7 @@ describe( 'CloudServices', () => {
 	} );
 
 	describe( 'init()', () => {
-		it( 'should expose option property based on config', () => {
+		it( 'should expose its properties based on config', () => {
 			return ClassicTestEditor
 				.create( element, {
 					plugins: [ CloudServices ],
@@ -46,7 +46,14 @@ describe( 'CloudServices', () => {
 				} );
 		} );
 
-		it( 'should provide token', () => {
+		it( 'should not throw an error when no config is provided', () => {
+			return ClassicTestEditor
+				.create( element, {
+					plugins: [ CloudServices ]
+				} );
+		} );
+
+		it( 'should provide token if tokenUrl is provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
 			return ClassicTestEditor
@@ -65,18 +72,18 @@ describe( 'CloudServices', () => {
 				} );
 		} );
 
-		it( 'should throw an error when token URL is not provided', done => {
+		it( 'should not provide token if tokenUrl is not provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
-			ClassicTestEditor
+			return ClassicTestEditor
 				.create( element, {
 					plugins: [ CloudServices ],
 					cloudServices: {}
 				} )
-				.catch( err => {
-					expect( err.name ).to.equal( 'CKEditorError' );
-					expect( err.message, '12' ).to.match( /cloudservices-token-endpoint-not-provided/ );
-					done();
+				.then( editor => {
+					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+
+					expect( cloudServicesPlugin.token ).to.equal( null );
 				} );
 		} );
 	} );