Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add published_at attribute to published resources #558

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/streaming/entities/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { CONFIG: configConstants } = require('../../common/consts'),

class StreamingMessage {
constructor(metadata, event, resource) {
this.published_at = new Date();
this.metadata = metadata;
this.event = event;
this.resource = new StreamingResource(resource);
Expand All @@ -16,6 +17,7 @@ class StreamingMessage {
const defaultMetadata = await buildDefaultMetadata();
const metadata = { ...this.metadata, ...defaultMetadata };
return JSON.stringify({
published_at: this.published_at,
metadata: metadata,
event: this.event,
resource: resourceWithoutExcludedAttributes
Expand Down
6 changes: 5 additions & 1 deletion tests/unit-tests/streaming/manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { expect } = require('chai'),
uuid = require('uuid'),
rewire = require('rewire'),
sinon = require('sinon');

Expand All @@ -11,6 +10,7 @@ describe('health check', function() {
let sandbox;
let kafkaManagerInitStub, kafkaManagerHealthStub, kafkaManagerCloseStub, kafkaManagerProduceStub;
let configGetValueStub;
let newDateStub;

before(function() {
sandbox = sinon.createSandbox();
Expand All @@ -19,6 +19,7 @@ describe('health check', function() {
kafkaManagerCloseStub = sandbox.stub(kafkaManager, 'close');
kafkaManagerProduceStub = sandbox.stub(kafkaManager, 'produce');
configGetValueStub = sandbox.stub(configHandler, 'getConfigValue');
newDateStub = sandbox.stub(Date.prototype, 'constructor');
});
afterEach(() => {
sandbox.resetHistory();
Expand Down Expand Up @@ -142,6 +143,8 @@ describe('health check', function() {
});
configGetValueStub.resolves();
kafkaManagerProduceStub.resolves();
const newDate = new Date();
newDateStub.returns(newDate);

const metadata = {
'load-testing': 'v4'
Expand Down Expand Up @@ -192,6 +195,7 @@ describe('health check', function() {
await streamingManager.produce(metadata, event, resource);
expect(kafkaManagerProduceStub.calledOnce).eql(true);
expect(kafkaManagerProduceStub.args[0][0]).eql(JSON.stringify({
published_at: newDate,
metadata: {
'load-testing': 'v4',
'predator-version': '1.6.0'
Expand Down