Browse Source

Improved tests.

Maciej Bukowski 6 years ago
parent
commit
18fef09b73

+ 10 - 5
packages/ckeditor-cloud-services-core/src/uploadgateway/fileuploader.js

@@ -26,25 +26,30 @@ export default class FileUploader {
 	 */
 	constructor( fileOrData, token, apiAddress ) {
 		if ( !fileOrData ) {
-			throw new CKEditorError( 'File must be provided' );
+			/**
+			 * File must be provided as the first argument.
+			 *
+			 * @error fileuploader-missing-file
+			 */
+			throw new CKEditorError( 'fileuploader-missing-file: File must be provided as the first argument' );
 		}
 
 		if ( !token ) {
 			/**
-			 * Token must be provided.
+			 * Token must be provided as the second argument.
 			 *
 			 * @error fileuploader-missing-token
 			 */
-			throw new CKEditorError( 'fileuploader-missing-token: Token must be provided.' );
+			throw new CKEditorError( 'fileuploader-missing-token: Token must be provided as the second argument.' );
 		}
 
 		if ( !apiAddress ) {
 			/**
-			 * Api address must be provided.
+			 * Api address must be provided as the third argument.
 			 *
 			 * @error fileuploader-missing-api-address
 			 */
-			throw new CKEditorError( 'fileuploader-missing-api-address: Api address must be provided.' );
+			throw new CKEditorError( 'fileuploader-missing-api-address: Api address must be provided as the third argument.' );
 		}
 
 		/**

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

@@ -8,6 +8,7 @@
 'use strict';
 
 import Token from '../../src/token/token';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 describe( 'Token', () => {
 	let requests;
@@ -27,7 +28,8 @@ describe( 'Token', () => {
 	describe( 'constructor()', () => {
 		it( 'should throw error when no tokenUrl provided', () => {
 			expect( () => new Token() ).to.throw(
-				'A `tokenUrl` must be provided as the first constructor argument.'
+				CKEditorError,
+				'token-missing-token-url'
 			);
 		} );
 
@@ -159,7 +161,8 @@ describe( 'Token', () => {
 			return promise.then( () => {
 				throw new Error( 'Promise should be rejected' );
 			}, error => {
-				expect( error ).to.match( /Cannot download new token!/ );
+				expect( error.constructor ).to.equal( CKEditorError );
+				expect( error ).to.match( /token-cannot-download-new-token/ );
 			} );
 		} );
 

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

@@ -9,6 +9,7 @@
 
 import FileUploader from '../../src/uploadgateway/fileuploader';
 import Token from '../../src/token/token';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 const API_ADDRESS = 'https://example.dev';
 const BASE_64_FILE = 'data:image/gif;base64,R0lGODlhCQAJAPIAAGFhYZXK/1FRUf///' +
@@ -25,20 +26,20 @@ describe( 'FileUploader', () => {
 
 	describe( 'constructor()', () => {
 		it( 'should throw error when no fileOrData provided', () => {
-			expect( () => new FileUploader() ).to.throw( 'File must be provided' );
+			expect( () => new FileUploader() ).to.throw( CKEditorError, 'fileuploader-missing-file' );
 		} );
 
 		it( 'should throw error when no token provided', () => {
-			expect( () => new FileUploader( 'file' ) ).to.throw( 'Token must be provided' );
+			expect( () => new FileUploader( 'file' ) ).to.throw( CKEditorError, 'fileuploader-missing-token' );
 		} );
 
 		it( 'should throw error when no api address provided', () => {
-			expect( () => new FileUploader( 'file', token ) ).to.throw( 'Api address must be provided' );
+			expect( () => new FileUploader( 'file', token ) ).to.throw( CKEditorError, 'fileuploader-missing-api-address' );
 		} );
 
 		it( 'should throw error when wrong Base64 file is provided', () => {
 			expect( () => new FileUploader( 'data:image/gif;base64,R', token, API_ADDRESS ) )
-				.to.throw( 'Problem with decoding Base64 image data.' );
+				.to.throw( CKEditorError, 'fileuploader-decoding-image-data-error' );
 		} );
 
 		it( 'should convert base64 to file', done => {

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

@@ -8,17 +8,18 @@
 import FileUploader from '../../src/uploadgateway/fileuploader';
 import UploadGateway from '../../src/uploadgateway/uploadgateway';
 import Token from '../../src/token/token';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 describe( 'UploadGateway', () => {
 	const token = new Token( 'url', { initValue: 'token', autoRefresh: false } );
 
 	describe( 'constructor()', () => {
 		it( 'should throw error when no token provided', () => {
-			expect( () => new UploadGateway( undefined, 'test' ) ).to.throw( 'Token must be provided' );
+			expect( () => new UploadGateway( undefined, 'test' ) ).to.throw( CKEditorError, 'uploadgateway-missing-token' );
 		} );
 
 		it( 'should throw error when no apiAddress provided', () => {
-			expect( () => new UploadGateway( token ) ).to.throw( 'Api address must be provided' );
+			expect( () => new UploadGateway( token ) ).to.throw( CKEditorError, 'uploadgateway-missing-api-address' );
 		} );
 	} );