Skip to content

Commit

Permalink
test: Add, fix tests for Script
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas committed Oct 1, 2018
1 parent 0ff9f99 commit 8d7d13b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions test/core-test/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { makeSetsOptionMacro } from '../_macros';
const setsOption = makeSetsOptionMacro(script);

test(setsOption, 'inline', { param: "doc['my_field'] * multiplier" });
test(setsOption, 'source', { param: "doc['my_field'] * multiplier" });
test(setsOption, 'file', { param: 'calculate-score' });
test(setsOption, 'stored', { param: 'calculate-score' });
test(setsOption, 'id', { param: 'calculate-score' });
test(setsOption, 'lang', { param: 'painless' });
test(setsOption, 'params', { param: { my_modifier: 2 } });

Expand All @@ -26,6 +28,15 @@ test('constructor sets arguments', t => {
};
t.deepEqual(valueA, expected);

valueA = new Script('source', 'params.my_var1 / params.my_var2').toJSON();
valueB = new Script().source('params.my_var1 / params.my_var2').toJSON();
t.deepEqual(valueA, valueB);

expected = {
source: 'params.my_var1 / params.my_var2'
};
t.deepEqual(valueA, expected);

valueA = new Script('file', 'calculate-score').toJSON();
valueB = new Script().file('calculate-score').toJSON();
t.deepEqual(valueA, valueB);
Expand All @@ -39,9 +50,14 @@ test('constructor sets arguments', t => {
valueB = new Script().stored('calculate-score').toJSON();
t.deepEqual(valueA, valueB);

expected = {
stored: 'calculate-score'
};
expected = { stored: 'calculate-score' };
t.deepEqual(valueA, expected);

valueA = new Script('id', 'calculate-score').toJSON();
valueB = new Script().id('calculate-score').toJSON();
t.deepEqual(valueA, valueB);

expected = { id: 'calculate-score' };
t.deepEqual(valueA, expected);

const err = t.throws(() => new Script('invalid_script_type', 'src'), Error);
Expand All @@ -63,7 +79,7 @@ test.serial('mixed representaion', t => {
t.true(spy.calledTwice);
t.true(
spy.firstCall.calledWith(
'[Script] Script source(`inline`/`stored`/`file`) was already specified!'
'[Script] Script source(`inline`/`source`/`stored`/`id`/`file`) was already specified!'
)
);
t.true(spy.secondCall.calledWith('[Script] Overwriting.'));
Expand Down

0 comments on commit 8d7d13b

Please sign in to comment.