Skip to content

Commit 912ece2

Browse files
committed
test: update unit tests
1 parent 091f74c commit 912ece2

File tree

3 files changed

+107
-12
lines changed

3 files changed

+107
-12
lines changed

test/unit/assistant.v1.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,12 @@ describe('getWorkspace', () => {
282282
const workspace_id = 'fake_workspace_id';
283283
const _export = 'fake_export';
284284
const include_audit = 'fake_include_audit';
285+
const sort = 'fake_sort';
285286
const params = {
286287
workspace_id,
287288
export: _export,
288289
include_audit,
290+
sort,
289291
};
290292

291293
// invoke method
@@ -303,6 +305,7 @@ describe('getWorkspace', () => {
303305
checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType);
304306
expect(options.qs['export']).toEqual(_export);
305307
expect(options.qs['include_audit']).toEqual(include_audit);
308+
expect(options.qs['sort']).toEqual(sort);
306309
expect(options.path['workspace_id']).toEqual(workspace_id);
307310
});
308311

test/unit/discovery.v1.test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,83 @@ describe('deleteTokenizationDictionary', () => {
19031903
});
19041904
});
19051905
});
1906+
describe('getStopwordListStatus', () => {
1907+
describe('positive tests', () => {
1908+
beforeAll(() => {
1909+
missingParamsMock.mockReturnValue(missingParamsSuccess);
1910+
});
1911+
test('should pass the right params to createRequest', () => {
1912+
// parameters
1913+
const environment_id = 'fake_environment_id';
1914+
const collection_id = 'fake_collection_id';
1915+
const params = {
1916+
environment_id,
1917+
collection_id,
1918+
};
1919+
1920+
// invoke method
1921+
discovery.getStopwordListStatus(params);
1922+
1923+
// assert that create request was called
1924+
expect(createRequestMock).toHaveBeenCalledTimes(1);
1925+
1926+
const options = getOptions(createRequestMock);
1927+
1928+
checkUrlAndMethod(
1929+
options,
1930+
'/v1/environments/{environment_id}/collections/{collection_id}/word_lists/stopwords',
1931+
'GET'
1932+
);
1933+
checkCallback(createRequestMock);
1934+
const expectedAccept = 'application/json';
1935+
const expectedContentType = 'application/json';
1936+
checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType);
1937+
expect(options.path['environment_id']).toEqual(environment_id);
1938+
expect(options.path['collection_id']).toEqual(collection_id);
1939+
});
1940+
1941+
test('should prioritize user-given headers', () => {
1942+
// parameters
1943+
const environment_id = 'fake_environment_id';
1944+
const collection_id = 'fake_collection_id';
1945+
const accept = 'fake/header';
1946+
const contentType = 'fake/header';
1947+
const params = {
1948+
environment_id,
1949+
collection_id,
1950+
headers: {
1951+
Accept: accept,
1952+
'Content-Type': contentType,
1953+
},
1954+
};
1955+
1956+
discovery.getStopwordListStatus(params);
1957+
checkMediaHeaders(createRequestMock, accept, contentType);
1958+
});
1959+
});
1960+
describe('negative tests', () => {
1961+
beforeAll(() => {
1962+
missingParamsMock.mockReturnValue(missingParamsError);
1963+
});
1964+
1965+
test('should convert a `null` value for `params` to an empty object', done => {
1966+
discovery.getStopwordListStatus(null, () => {
1967+
checkForEmptyObject(missingParamsMock);
1968+
done();
1969+
});
1970+
});
1971+
1972+
test('should enforce required parameters', done => {
1973+
// required parameters for this method
1974+
const requiredParams = ['environment_id', 'collection_id'];
1975+
1976+
discovery.getStopwordListStatus({}, err => {
1977+
checkRequiredParamsHandling(requiredParams, err, missingParamsMock, createRequestMock);
1978+
done();
1979+
});
1980+
});
1981+
});
1982+
});
19061983
describe('getTokenizationDictionaryStatus', () => {
19071984
describe('positive tests', () => {
19081985
beforeAll(() => {

test/unit/speech-to-text.v1.test.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('recognize', () => {
161161
const audio = 'fake_audio';
162162
const content_type = 'fake_content_type';
163163
const model = 'fake_model';
164-
const customization_id = 'fake_customization_id';
164+
const language_customization_id = 'fake_language_customization_id';
165165
const acoustic_customization_id = 'fake_acoustic_customization_id';
166166
const base_model_version = 'fake_base_model_version';
167167
const customization_weight = 'fake_customization_weight';
@@ -175,11 +175,14 @@ describe('recognize', () => {
175175
const profanity_filter = 'fake_profanity_filter';
176176
const smart_formatting = 'fake_smart_formatting';
177177
const speaker_labels = 'fake_speaker_labels';
178+
const customization_id = 'fake_customization_id';
179+
const grammar_name = 'fake_grammar_name';
180+
const redaction = 'fake_redaction';
178181
const params = {
179182
audio,
180183
content_type,
181184
model,
182-
customization_id,
185+
language_customization_id,
183186
acoustic_customization_id,
184187
base_model_version,
185188
customization_weight,
@@ -193,6 +196,9 @@ describe('recognize', () => {
193196
profanity_filter,
194197
smart_formatting,
195198
speaker_labels,
199+
customization_id,
200+
grammar_name,
201+
redaction,
196202
};
197203

198204
// invoke method
@@ -212,7 +218,7 @@ describe('recognize', () => {
212218
expect(options.body).toEqual(audio);
213219
expect(options.json).toEqual(content_type === 'application/json');
214220
expect(options.qs['model']).toEqual(model);
215-
expect(options.qs['customization_id']).toEqual(customization_id);
221+
expect(options.qs['language_customization_id']).toEqual(language_customization_id);
216222
expect(options.qs['acoustic_customization_id']).toEqual(acoustic_customization_id);
217223
expect(options.qs['base_model_version']).toEqual(base_model_version);
218224
expect(options.qs['customization_weight']).toEqual(customization_weight);
@@ -226,17 +232,18 @@ describe('recognize', () => {
226232
expect(options.qs['profanity_filter']).toEqual(profanity_filter);
227233
expect(options.qs['smart_formatting']).toEqual(smart_formatting);
228234
expect(options.qs['speaker_labels']).toEqual(speaker_labels);
235+
expect(options.qs['customization_id']).toEqual(customization_id);
236+
expect(options.qs['grammar_name']).toEqual(grammar_name);
237+
expect(options.qs['redaction']).toEqual(redaction);
229238
});
230239

231240
test('should prioritize user-given headers', () => {
232241
// parameters
233242
const audio = 'fake_audio';
234-
const content_type = 'fake_content_type';
235243
const accept = 'fake/header';
236244
const contentType = 'fake/header';
237245
const params = {
238246
audio,
239-
content_type,
240247
headers: {
241248
Accept: accept,
242249
'Content-Type': contentType,
@@ -403,7 +410,7 @@ describe('createJob', () => {
403410
const events = 'fake_events';
404411
const user_token = 'fake_user_token';
405412
const results_ttl = 'fake_results_ttl';
406-
const customization_id = 'fake_customization_id';
413+
const language_customization_id = 'fake_language_customization_id';
407414
const acoustic_customization_id = 'fake_acoustic_customization_id';
408415
const base_model_version = 'fake_base_model_version';
409416
const customization_weight = 'fake_customization_weight';
@@ -417,6 +424,9 @@ describe('createJob', () => {
417424
const profanity_filter = 'fake_profanity_filter';
418425
const smart_formatting = 'fake_smart_formatting';
419426
const speaker_labels = 'fake_speaker_labels';
427+
const customization_id = 'fake_customization_id';
428+
const grammar_name = 'fake_grammar_name';
429+
const redaction = 'fake_redaction';
420430
const params = {
421431
audio,
422432
content_type,
@@ -425,7 +435,7 @@ describe('createJob', () => {
425435
events,
426436
user_token,
427437
results_ttl,
428-
customization_id,
438+
language_customization_id,
429439
acoustic_customization_id,
430440
base_model_version,
431441
customization_weight,
@@ -439,6 +449,9 @@ describe('createJob', () => {
439449
profanity_filter,
440450
smart_formatting,
441451
speaker_labels,
452+
customization_id,
453+
grammar_name,
454+
redaction,
442455
};
443456

444457
// invoke method
@@ -462,7 +475,7 @@ describe('createJob', () => {
462475
expect(options.qs['events']).toEqual(events);
463476
expect(options.qs['user_token']).toEqual(user_token);
464477
expect(options.qs['results_ttl']).toEqual(results_ttl);
465-
expect(options.qs['customization_id']).toEqual(customization_id);
478+
expect(options.qs['language_customization_id']).toEqual(language_customization_id);
466479
expect(options.qs['acoustic_customization_id']).toEqual(acoustic_customization_id);
467480
expect(options.qs['base_model_version']).toEqual(base_model_version);
468481
expect(options.qs['customization_weight']).toEqual(customization_weight);
@@ -476,17 +489,18 @@ describe('createJob', () => {
476489
expect(options.qs['profanity_filter']).toEqual(profanity_filter);
477490
expect(options.qs['smart_formatting']).toEqual(smart_formatting);
478491
expect(options.qs['speaker_labels']).toEqual(speaker_labels);
492+
expect(options.qs['customization_id']).toEqual(customization_id);
493+
expect(options.qs['grammar_name']).toEqual(grammar_name);
494+
expect(options.qs['redaction']).toEqual(redaction);
479495
});
480496

481497
test('should prioritize user-given headers', () => {
482498
// parameters
483499
const audio = 'fake_audio';
484-
const content_type = 'fake_content_type';
485500
const accept = 'fake/header';
486501
const contentType = 'fake/header';
487502
const params = {
488503
audio,
489-
content_type,
490504
headers: {
491505
Accept: accept,
492506
'Content-Type': contentType,
@@ -2629,9 +2643,11 @@ describe('upgradeAcousticModel', () => {
26292643
// parameters
26302644
const customization_id = 'fake_customization_id';
26312645
const custom_language_model_id = 'fake_custom_language_model_id';
2646+
const force = 'fake_force';
26322647
const params = {
26332648
customization_id,
26342649
custom_language_model_id,
2650+
force,
26352651
};
26362652

26372653
// invoke method
@@ -2652,6 +2668,7 @@ describe('upgradeAcousticModel', () => {
26522668
const expectedContentType = 'application/json';
26532669
checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType);
26542670
expect(options.qs['custom_language_model_id']).toEqual(custom_language_model_id);
2671+
expect(options.qs['force']).toEqual(force);
26552672
expect(options.path['customization_id']).toEqual(customization_id);
26562673
});
26572674

@@ -2748,14 +2765,12 @@ describe('addAudio', () => {
27482765
const customization_id = 'fake_customization_id';
27492766
const audio_name = 'fake_audio_name';
27502767
const audio_resource = 'fake_audio_resource';
2751-
const content_type = 'fake_content_type';
27522768
const accept = 'fake/header';
27532769
const contentType = 'fake/header';
27542770
const params = {
27552771
customization_id,
27562772
audio_name,
27572773
audio_resource,
2758-
content_type,
27592774
headers: {
27602775
Accept: accept,
27612776
'Content-Type': contentType,

0 commit comments

Comments
 (0)