8
0

uploadgateway.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* eslint-env browser */
  6. import FileUploader from '../../src/uploadgateway/fileuploader';
  7. import UploadGateway from '../../src/uploadgateway/uploadgateway';
  8. import Token from '../../src/token/token';
  9. import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  10. describe( 'UploadGateway', () => {
  11. const tokenInitValue = `header.${ btoa( JSON.stringify( { exp: Date.now() + 3600000 } ) ) }.signature`;
  12. const token = new Token( 'url', { initValue: tokenInitValue, autoRefresh: false } );
  13. describe( 'constructor()', () => {
  14. it( 'should throw error when no token provided', () => {
  15. expectToThrowCKEditorError( () => new UploadGateway( undefined, 'test' ), 'uploadgateway-missing-token' );
  16. } );
  17. it( 'should throw error when no apiAddress provided', () => {
  18. expectToThrowCKEditorError( () => new UploadGateway( token ), 'uploadgateway-missing-api-address' );
  19. } );
  20. } );
  21. describe( 'upload()', () => {
  22. it( 'should return `FileUploader` instance', () => {
  23. const uploader = new UploadGateway( token, 'test' );
  24. expect( uploader.upload( 'file' ) ).to.be.instanceOf( FileUploader );
  25. } );
  26. } );
  27. } );