@codefresh-io/authenticated-entity
Advanced tools
Comparing version 2.0.2 to 2.0.21
@@ -14,4 +14,8 @@ const crypto = require('crypto'); | ||
toJson() { | ||
return this._entity; | ||
toJson(options = {}) { | ||
if (options.partial) { | ||
return this._getPartialJson(); | ||
} else { | ||
return this._entity; | ||
} | ||
} | ||
@@ -40,2 +44,8 @@ | ||
} | ||
_getPartialJson() { | ||
return { | ||
type: this.getType(), | ||
}; | ||
} | ||
} | ||
@@ -42,0 +52,0 @@ |
@@ -19,2 +19,8 @@ const Entity = require('./Entity'); | ||
} | ||
_getPartialJson() { | ||
return Object.assign(super._getPartialJson(), { | ||
serviceName: this._entity.serviceName, | ||
}); | ||
} | ||
} | ||
@@ -21,0 +27,0 @@ |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const sinonChai = require('sinon-chai'); | ||
const sinon = require('sinon'); | ||
@@ -15,3 +16,6 @@ const expect = chai.expect; | ||
const System = require('../System'); | ||
const EntityTypes = require('./../Types'); | ||
EntityTypes.TEST = 'fake-type-for-testing'; | ||
chai.use(sinonChai); | ||
@@ -59,3 +63,19 @@ | ||
it('Should get json object', () => { | ||
const entity = new Entity({ type: EntityTypes.TEST }); | ||
expect(entity.toJson()).to.be.deep.equal({ | ||
type: EntityTypes.TEST, | ||
}); | ||
}); | ||
it('Should get partial json object', () => { | ||
const entity = new Entity({ type: EntityTypes.TEST }); | ||
entity._getPartialJson = sinon.spy(entity._getPartialJson); | ||
entity.toJson({ | ||
partial: true, | ||
}); | ||
expect(entity._getPartialJson).to.have.been.calledOnce; | ||
}); | ||
}); | ||
@@ -40,2 +40,10 @@ 'use strict'; | ||
it('should return a partial json object', () => { | ||
const system = new System('microservice'); | ||
expect(system.toJson({ partial: true })).to.deep.equal({ | ||
'serviceName': 'microservice', | ||
'type': 'system' | ||
}); | ||
}); | ||
it('should return a string for toString', () => { | ||
@@ -56,3 +64,5 @@ const system = new System('microservice'); | ||
}); | ||
@@ -103,2 +103,11 @@ 'use strict'; | ||
it('should get user partial object', () => { | ||
const user = User.constructFromUserEntity(fakeUserData()); | ||
expect(user.toJson({ partial: true })).to.be.deep.equal({ | ||
type: 'user', | ||
id: 'fake-user-id-1', | ||
name: 'fake-userName', | ||
}); | ||
}); | ||
it('should get only the minimum set of properties', () => { | ||
@@ -105,0 +114,0 @@ const user = User.constructFromUserEntity(_.merge(fakeUserData(), { key: 'val' })); |
@@ -75,2 +75,13 @@ const _ = require('lodash'); | ||
} | ||
getUserName() { | ||
return this._entity.name; | ||
} | ||
_getPartialJson() { | ||
return Object.assign(super._getPartialJson(), { | ||
id: this.getUserId(), | ||
name: this.getUserName(), | ||
}); | ||
} | ||
} | ||
@@ -77,0 +88,0 @@ |
{ | ||
"name": "@codefresh-io/authenticated-entity", | ||
"version": "2.0.2", | ||
"version": "2.0.21", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
231136
572