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(3266): fixed unit tests for banner #3270

Merged
merged 3 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"pretest": "eslint . --quiet",
"test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --reporter mocha-multi-reporters --reporter-options configFile=./mocha.config.json --recursive --timeout 10000 --retries 1 --exit --allow-uncaught true --color true",
"test-debug": "mocha --inspect-brk ./test/**/*.js",
"test-banner": "mocha ./test/plugins/banner.test.js",
"start": "./bin/server",
"debug": "node --nolazy ./bin/server",
"profile": "node --prof ./bin/server",
Expand Down Expand Up @@ -109,7 +110,7 @@
"screwdriver-config-parser": "^11.0.0",
"screwdriver-coverage-bookend": "^2.0.0",
"screwdriver-coverage-sonar": "^4.1.1",
"screwdriver-data-schema": "^24.1.0",
"screwdriver-data-schema": "^24.2.0",
"screwdriver-datastore-sequelize": "^9.0.0",
"screwdriver-executor-base": "^10.0.0",
"screwdriver-executor-docker": "^7.0.0",
Expand All @@ -118,7 +119,7 @@
"screwdriver-executor-queue": "^5.0.0",
"screwdriver-executor-router": "^4.0.0",
"screwdriver-logger": "^2.0.0",
"screwdriver-models": "^31.0.0",
"screwdriver-models": "^31.1.0",
"screwdriver-notifications-email": "^4.0.0",
"screwdriver-notifications-slack": "^6.0.0",
"screwdriver-request": "^2.0.1",
Expand Down
4 changes: 3 additions & 1 deletion test/plugins/banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('banner plugin test', () => {
const message = 'Test banner example';
const isActive = true;
const type = 'info';
const scope = 'GLOBAL';

beforeEach(() => {
options = {
Expand All @@ -112,7 +113,8 @@ describe('banner plugin test', () => {
payload: {
message,
isActive,
type
type,
scope
},
auth: {
credentials: {
Expand Down
85 changes: 85 additions & 0 deletions test/plugins/builds.triggers.helpers.test.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this file added by accident?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ooopss

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const { assert } = require('chai');
const { getSubsequentJobs } = require('../../plugins/builds/triggers/helpers');

('use strict');

describe('getSubsequentJobs', () => {
it('should return an empty array if startNode is not provided', () => {
const workflowGraph = {
nodes: [{ name: 'job1' }, { name: 'job2' }],
edges: [{ src: 'job1', dest: 'job2' }]
};

const result = getSubsequentJobs(workflowGraph);

assert.deepEqual(result, []);
});

it('should return an empty array if nodes are empty', () => {
const workflowGraph = {
nodes: [],
edges: [{ src: 'job1', dest: 'job2' }]
};

const result = getSubsequentJobs(workflowGraph, 'job1');

assert.deepEqual(result, []);
});

it('should return subsequent jobs correctly', () => {
const workflowGraph = {
nodes: [{ name: 'job1' }, { name: 'job2' }, { name: 'job3' }],
edges: [
{ src: 'job1', dest: 'job2' },
{ src: 'job2', dest: 'job3' }
]
};

const result = getSubsequentJobs(workflowGraph, 'job1');

assert.deepEqual(result, ['job2', 'job3']);
});

it('should handle circular dependencies gracefully', () => {
const workflowGraph = {
nodes: [{ name: 'job1' }, { name: 'job2' }, { name: 'job3' }],
edges: [
{ src: 'job1', dest: 'job2' },
{ src: 'job2', dest: 'job3' },
{ src: 'job3', dest: 'job1' }
]
};

const result = getSubsequentJobs(workflowGraph, 'job1');

assert.deepEqual(result, ['job2', 'job3']);
});

it('should handle jobs with tildes correctly', () => {
const workflowGraph = {
nodes: [{ name: '~job1' }, { name: 'job2' }, { name: 'job3' }],
edges: [
{ src: '~job1', dest: 'job2' },
{ src: 'job2', dest: 'job3' }
]
};

const result = getSubsequentJobs(workflowGraph, '~job1');

assert.deepEqual(result, ['job2', 'job3']);
});

it('should handle jobs with different start tildes correctly', () => {
const workflowGraph = {
nodes: [{ name: 'job1' }, { name: '~job2' }, { name: 'job3' }],
edges: [
{ src: 'job1', dest: '~job2' },
{ src: '~job2', dest: 'job3' }
]
};

const result = getSubsequentJobs(workflowGraph, 'job1');

assert.deepEqual(result, ['~job2', 'job3']);
});
});
2 changes: 2 additions & 0 deletions test/plugins/data/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"message": "Test banner example",
"isActive": true,
"type": "info",
"scope": "GLOBAL",
"scopeId": null,
"createdBy": "jimgrund",
"createTime": "2017-01-06T01:49:50.384359267Z"
}
2 changes: 2 additions & 0 deletions test/plugins/data/banners-active.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"message": "Test banner example",
"type": "info",
"isActive": true,
"scope": "GLOBAL",
"scopeId": null,
"createdBy": "batman123",
"createTime": "2017-01-06T01:49:50.384359267Z"
}
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/data/banners.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"message": "Test banner example",
"type": "info",
"isActive": true,
"scope": "GLOBAL",
"scopeId": null,
"createdBy": "batman123",
"createTime": "2017-01-06T01:49:50.384359267Z"
},
Expand All @@ -12,6 +14,8 @@
"message": "Test banner example again",
"type": "info",
"isActive": false,
"scope": "GLOBAL",
"scopeId": null,
"createdBy": "batman123",
"createTime": "2017-01-07T01:49:50.384359267Z"
},
Expand All @@ -20,6 +24,8 @@
"message": "Test banner example yet again",
"type": "warn",
"isActive": false,
"scope": "GLOBAL",
"scopeId": null,
"createdBy": "batman123",
"createTime": "2017-01-08T01:49:50.384359267Z"
}
Expand Down