-
Notifications
You must be signed in to change notification settings - Fork 6
/
translations-upload.js
79 lines (65 loc) · 2.01 KB
/
translations-upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @license Copyright (c) 2020-2022, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
'use strict';
const sinon = require( 'sinon' );
const expect = require( 'chai' ).expect;
const mockery = require( 'mockery' );
describe( 'lib/tasks/translations-upload', () => {
let translationsUpload, stubs;
beforeEach( () => {
mockery.enable( {
useCleanCache: true,
warnOnReplace: false,
warnOnUnregistered: false
} );
stubs = {
getToken: sinon.stub(),
devEnv: {
uploadPotFiles: sinon.stub()
},
path: {
join: sinon.stub().callsFake( ( ...chunks ) => chunks.join( '/' ) )
}
};
mockery.registerMock( 'path', stubs.path );
mockery.registerMock( 'glob', stubs.glob );
mockery.registerMock( '@ckeditor/ckeditor5-dev-env', stubs.devEnv );
mockery.registerMock( '@ckeditor/ckeditor5-dev-env/lib/translations/gettoken', stubs.getToken );
translationsUpload = require( '../../lib/tasks/translations-upload' );
} );
afterEach( () => {
sinon.restore();
mockery.disable();
} );
it( 'should be a function', () => {
expect( translationsUpload ).to.be.a( 'function' );
} );
it( 'uploads translation files', async () => {
stubs.getToken.resolves( 'secretToken' );
stubs.devEnv.uploadPotFiles.resolves( 'OK' );
const results = await translationsUpload( {
cwd: '/workspace',
transifex: 'https://api.example.com'
} );
expect( results ).to.equal( 'OK' );
expect( stubs.devEnv.uploadPotFiles.calledOnce ).to.equal( true );
expect( stubs.devEnv.uploadPotFiles.firstCall.firstArg ).to.deep.equal( {
token: 'secretToken',
translationsDirectory: '/workspace/tmp/.transifex',
url: 'https://api.example.com'
} );
} );
it( 'throws an error if the "transifex" option is not specified', async () => {
try {
await translationsUpload( {
cwd: '/workspace'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The URL to the Transifex API is required. Use --transifex [API end-point] to provide the value.'
);
}
} );
} );