-
Notifications
You must be signed in to change notification settings - Fork 169
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): functional tests for banner API #3273
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
47163e2
fixed unit tests for banner
VonnyJap db6916f
removed test/plugins/builds.triggers.helpers.test.js
VonnyJap 1aab0e1
removed test-banner in package.json
VonnyJap 70e722e
add functional tests for banner
VonnyJap fc9ca6c
add functional tests for banner creating pipeline scope
VonnyJap 1c519b1
removed commented lines
VonnyJap 4bd10b6
removed commented line
VonnyJap 12f3f90
Update features/banner.feature
VonnyJap 9790b99
Update features/banner.feature
VonnyJap ffe197d
add more tests
VonnyJap 2be258d
fixed linting
VonnyJap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@banner | ||
@parallel | ||
Feature: Banner | ||
|
||
Banners are used by Screwdriver admins to notify users about important updates or changes. | ||
This feature ensures that all users are aware of critical information, such as system maintenance, new feature releases, or any other relevant announcements. | ||
By using banners, admins can effectively communicate with users and ensure that they are informed in a timely manner. | ||
|
||
Rules: | ||
- Only users with Screwdriver admin permissions can create banners. | ||
- Banners can be scoped as Global, Pipeline, or Build. | ||
- Once a banner is created, its scope cannot be changed. | ||
- When a banner is created with Pipeline or Build scope, a scopeId is required. | ||
- The banner message can be updated. | ||
- Banners can be deleted. | ||
|
||
Background: | ||
Given "calvin" is logged in | ||
|
||
Scenario: Banner with global scope | ||
When they create new banner with message "Hello World" and "GLOBAL" scope | ||
Then they can see that the banner is created with "GLOBAL" scope | ||
And banner is "updated" when they update the banner with "message" "Some Random Message" | ||
And banner is "not updated" when they update the banner with "scopeId" "1234" | ||
And banner is "not updated" when they update the banner with "scope" "PIPELINE" | ||
Then banner is deleted | ||
|
||
Scenario: Banner with pipeline scope | ||
Given an existing pipeline | ||
And there is no banner associated to that pipeline | ||
When they create new banner with message "Hello World" and "PIPELINE" scope | ||
Then they can see that the banner is created with "PIPELINE" scope | ||
And they can get the banner associated to that pipeline | ||
And banner is "updated" when they update the banner with "isActive" "false" | ||
And banner is "not updated" when they update the banner with "scope" "GLOBAL" | ||
Then banner is deleted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
'use strict'; | ||
|
||
const Assert = require('chai').assert; | ||
const { Before, Then, When } = require('@cucumber/cucumber'); | ||
const request = require('screwdriver-request'); | ||
const { disableRunScenarioInParallel } = require('../support/parallel'); | ||
|
||
const TIMEOUT = 240 * 1000; | ||
|
||
disableRunScenarioInParallel(); | ||
|
||
Before('@banner', function hook() { | ||
this.jwt = null; | ||
this.bannerId = null; | ||
|
||
this.repoOrg = this.testOrg; | ||
this.repoName = 'functional-git'; | ||
this.pipelineId = null; | ||
}); | ||
|
||
When( | ||
/^they create new banner with message "([^"]*)" and "(GLOBAL|PIPELINE)" scope$/, | ||
{ timeout: TIMEOUT }, | ||
function step(message, scope) { | ||
const payload = { | ||
message, | ||
isActive: true, | ||
type: 'info' | ||
}; | ||
|
||
if (scope === 'PIPELINE') { | ||
payload.scope = scope; | ||
payload.scopeId = this.pipelineId; | ||
} | ||
|
||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners`, | ||
method: 'POST', | ||
json: payload, | ||
context: { | ||
token: this.jwt | ||
} | ||
}).then(resp => { | ||
Assert.equal(resp.statusCode, 201); | ||
Assert.equal(resp.body.message, message); | ||
Assert.equal(resp.body.isActive, true); | ||
Assert.equal(resp.body.type, 'info'); | ||
Assert.isNotNull(resp.body.id); | ||
this.bannerId = resp.body.id; | ||
}); | ||
} | ||
); | ||
|
||
Then( | ||
/^they can see that the banner is created with "(GLOBAL|PIPELINE)" scope$/, | ||
{ timeout: TIMEOUT }, | ||
function step(scope) { | ||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners/${this.bannerId}`, | ||
method: 'GET', | ||
context: { | ||
token: this.jwt | ||
} | ||
}).then(resp => { | ||
Assert.equal(resp.statusCode, 200); | ||
if (scope === 'PIPELINE') { | ||
Assert.equal(resp.body.scope, scope.toUpperCase()); | ||
Assert.equal(resp.body.scopeId, this.pipelineId); | ||
|
||
return; | ||
} | ||
Assert.equal(resp.body.scope, 'GLOBAL'); | ||
}); | ||
} | ||
); | ||
|
||
Then( | ||
/^banner is "(updated|not updated)" when they update the banner with "(message|scopeId|isActive|scope)" "([^"]*)"$/, | ||
{ timeout: TIMEOUT }, | ||
function step(status, payloadType, payloadValue) { | ||
const payload = {}; | ||
|
||
payload[payloadType] = payloadValue; | ||
|
||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners/${this.bannerId}`, | ||
method: 'PUT', | ||
json: payload, | ||
context: { | ||
token: this.jwt | ||
} | ||
}) | ||
.then(resp => { | ||
if (status === 'updated') { | ||
Assert.equal(resp.statusCode, 200); | ||
Assert.equal(resp.body[payloadType].toString(), payloadValue); | ||
} else { | ||
throw new Error('Banner should not be updated'); | ||
} | ||
}) | ||
.catch(err => { | ||
if (status === 'not updated') { | ||
Assert.equal(err.statusCode, 400); | ||
Assert.include(err.message, 'Invalid request payload input'); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
} | ||
); | ||
|
||
Then(/^banner is deleted$/, { timeout: TIMEOUT }, function step() { | ||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners/${this.bannerId}`, | ||
method: 'DELETE', | ||
context: { | ||
token: this.jwt | ||
} | ||
}).then(resp => { | ||
Assert.equal(resp.statusCode, 204); | ||
this.bannerId = null; | ||
}); | ||
}); | ||
|
||
Then(/^there is no banner associated to that pipeline$/, { timeout: TIMEOUT }, function step() { | ||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners?scopeId=${this.pipelineId}`, | ||
method: 'GET', | ||
context: { | ||
token: this.jwt | ||
} | ||
}).then(resp => { | ||
Assert.equal(resp.statusCode, 200); | ||
Assert.equal(resp.body.length, 0); | ||
}); | ||
}); | ||
|
||
Then(/^they can get the banner associated to that pipeline$/, { timeout: TIMEOUT }, function step() { | ||
return request({ | ||
url: `${this.instance}/${this.namespace}/banners?scopeId=${this.pipelineId}&scope=PIPELINE`, | ||
method: 'GET', | ||
context: { | ||
token: this.jwt | ||
} | ||
}).then(resp => { | ||
Assert.equal(resp.statusCode, 200); | ||
Assert.equal(resp.body.length, 1); | ||
Assert.equal(resp.body[0].scopeId, this.pipelineId); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also ensure that
scope
is immutable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
screwdriver/features/banner.feature
Line 25 in ffe197d