Skip to content

Commit

Permalink
Added unit tests for secret type variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-sharma-08 committed Sep 25, 2023
1 parent 56f36ab commit 520d5aa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/unit/mutation-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ describe('MutationTracker', function () {
it('should not track invalid mutation format', function () {
var tracker = new MutationTracker();

// expected signature is two parameters
tracker.track('set', 'foo', 'bar', 'baz');
// expected signature is three parameters
tracker.track('set', 'foo', 'bar', 'secret', 'baz');

expect(tracker.count()).to.eql(0);
});
Expand Down
40 changes: 40 additions & 0 deletions test/unit/variable-scope.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,18 @@ describe('VariableScope', function () {
expect(scope.mutations.count()).to.equal(1);
});

it('should track set operations with datatype when datatype is secret', function () {
var scope = new VariableScope();

scope.enableTracking();

scope.set('foo', 'bar', 'secret');

expect(scope).to.have.property('mutations');
expect(scope.mutations.count()).to.equal(1);
expect(scope.mutations.stream[0].length).to.equal(3);
});

it('should track unset operations', function () {
var scope = new VariableScope({
values: [{
Expand Down Expand Up @@ -1379,6 +1391,34 @@ describe('VariableScope', function () {
expect(scope1.values).to.eql(scope2.values);
});

it('should be capable of being replayed with secret datatype', function () {
var initialState = {
values: [{
key: 'foo',
value: 'foo'
}, {
key: 'bar',
value: 'bar'
}]
},
scope1 = new VariableScope(initialState),
scope2 = new VariableScope(initialState);

scope1.enableTracking();

// add a new key
scope1.set('baz', 'baz', 'secret');
// update a key
scope1.set('foo', 'foo updated', 'secret');
// remove a key
scope1.unset('bar');

// replay mutations on a different object
scope1.mutations.applyOn(scope2);

expect(scope1.values).to.eql(scope2.values);
});

it('should be serialized', function () {
var scope = new VariableScope(),
serialized,
Expand Down
26 changes: 26 additions & 0 deletions test/unit/variable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ describe('Variable', function () {
});
});

it('should prepopulate value and type when passed to the constructor (secret)', function () {
let v = new Variable({
value: 'Picard',
type: 'secret'
});

expect(v).to.deep.include({
value: 'Picard',
type: 'secret'
});
});

it('should typecast value during construction when type is provided (number)', function () {
var v = new Variable({
value: '108',
Expand Down Expand Up @@ -227,6 +239,20 @@ describe('Variable', function () {
expect(v.get()).to.equal(jsonValue);
});

it('should support any data type if type is set to `secret`', function () {
var v = new Variable({ type: 'secret' }),
jsonValue = { iam: 'json' };

v.set('Picard');
expect(v.get()).to.equal('Picard');

v.set(3.142);
expect(v.get()).to.equal(3.142);

v.set(jsonValue);
expect(v.get()).to.equal(jsonValue);
});

it('should type cast values to the specific type set', function () {
var v = new Variable({
type: 'string'
Expand Down

0 comments on commit 520d5aa

Please sign in to comment.