-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[chocolatey powershellgallery] add service tests for NuGet v2 services #1487
Changes from all commits
4656745
524a57e
21903e0
fdd6af4
0279848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,171 @@ | ||||||
'use strict'; | ||||||
|
||||||
const Joi = require('joi'); | ||||||
const ServiceTester = require('./runner/service-tester'); | ||||||
const { | ||||||
isMetric, | ||||||
isVPlusDottedVersionNClauses | ||||||
} = require('./helpers/validators'); | ||||||
const colorscheme = require('../lib/colorscheme.json'); | ||||||
const { | ||||||
versionJsonWithDash, | ||||||
versionJsonFirstCharZero, | ||||||
versionJsonFirstCharNotZero | ||||||
} = require('./helpers/nuget-fixtures.js'); | ||||||
const { invalidJSON } = require('./helpers/response-fixtures'); | ||||||
|
||||||
const t = new ServiceTester({ id: 'chocolatey', title: 'Chocolatey' }); | ||||||
module.exports = t; | ||||||
|
||||||
|
||||||
// downloads | ||||||
|
||||||
t.create('total downloads (valid)') | ||||||
.get('/dt/scriptcs.json') | ||||||
.expectJSONTypes(Joi.object().keys({ | ||||||
name: 'chocolatey', | ||||||
value: isMetric, | ||||||
})); | ||||||
|
||||||
t.create('total downloads (not found)') | ||||||
.get('/dt/not-a-real-package.json') | ||||||
.expectJSON({name: 'chocolatey', value: 'not found'}); | ||||||
|
||||||
t.create('total downloads (connection error)') | ||||||
.get('/dt/scriptcs.json') | ||||||
.networkOff() | ||||||
.expectJSON({name: 'chocolatey', value: 'inaccessible'}); | ||||||
|
||||||
t.create('total downloads (unexpected response)') | ||||||
.get('/dt/scriptcs.json') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true") | ||||||
.reply(invalidJSON) | ||||||
) | ||||||
.expectJSON({name: 'chocolatey', value: 'invalid'}); | ||||||
|
||||||
|
||||||
// version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "version" and "pre version" badge can have different colors (yellow, orange or blue). Would you like to test these cases? Color value can be check using this approach shields/service-tests/github.js Lines 39 to 40 in 8ad176d
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had not realised that it we had an endpoint to test the colours but I now see you added this in #1190 - this would probably be helpful in some other tests. I think it would also be helpful to add an example to the testing docs to explain this feature for other contributors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. I will try to add such example. |
||||||
|
||||||
t.create('version (valid)') | ||||||
.get('/v/scriptcs.json') | ||||||
.expectJSONTypes(Joi.object().keys({ | ||||||
name: 'chocolatey', | ||||||
value: isVPlusDottedVersionNClauses, | ||||||
})); | ||||||
|
||||||
t.create('version (mocked, yellow badge)') | ||||||
.get('/v/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonWithDash) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v1.2-beta', | ||||||
colorB: colorscheme.yellow.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (mocked, orange badge)') | ||||||
.get('/v/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonFirstCharZero) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v0.35', | ||||||
colorB: colorscheme.orange.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (mocked, blue badge)') | ||||||
.get('/v/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonFirstCharNotZero) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v1.2.7', | ||||||
colorB: colorscheme.blue.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (not found)') | ||||||
.get('/v/not-a-real-package.json') | ||||||
.expectJSON({name: 'chocolatey', value: 'not found'}); | ||||||
|
||||||
t.create('version (connection error)') | ||||||
.get('/v/scriptcs.json') | ||||||
.networkOff() | ||||||
.expectJSON({name: 'chocolatey', value: 'inaccessible'}); | ||||||
|
||||||
t.create('version (unexpected response)') | ||||||
.get('/v/scriptcs.json') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true") | ||||||
.reply(invalidJSON) | ||||||
) | ||||||
.expectJSON({name: 'chocolatey', value: 'invalid'}); | ||||||
|
||||||
|
||||||
// version (pre) | ||||||
|
||||||
t.create('version (pre) (valid)') | ||||||
.get('/vpre/scriptcs.json') | ||||||
.expectJSONTypes(Joi.object().keys({ | ||||||
name: 'chocolatey', | ||||||
value: isVPlusDottedVersionNClauses, | ||||||
})); | ||||||
|
||||||
t.create('version (pre) (mocked, yellow badge)') | ||||||
.get('/vpre/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonWithDash) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v1.2-beta', | ||||||
colorB: colorscheme.yellow.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (pre) (mocked, orange badge)') | ||||||
.get('/vpre/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonFirstCharZero) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v0.35', | ||||||
colorB: colorscheme.orange.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (pre) (mocked, blue badge)') | ||||||
.get('/vpre/scriptcs.json?style=_shields_test') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true") | ||||||
.reply(200, versionJsonFirstCharNotZero) | ||||||
) | ||||||
.expectJSON({ | ||||||
name: 'chocolatey', | ||||||
value: 'v1.2.7', | ||||||
colorB: colorscheme.blue.colorB | ||||||
}); | ||||||
|
||||||
t.create('version (pre) (not found)') | ||||||
.get('/vpre/not-a-real-package.json') | ||||||
.expectJSON({name: 'chocolatey', value: 'not found'}); | ||||||
|
||||||
t.create('version (pre) (connection error)') | ||||||
.get('/vpre/scriptcs.json') | ||||||
.networkOff() | ||||||
.expectJSON({name: 'chocolatey', value: 'inaccessible'}); | ||||||
|
||||||
t.create('version (pre) (unexpected response)') | ||||||
.get('/vpre/scriptcs.json') | ||||||
.intercept(nock => nock('https://www.chocolatey.org') | ||||||
.get("/api/v2/Packages()?$filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true") | ||||||
.reply(invalidJSON) | ||||||
) | ||||||
.expectJSON({name: 'chocolatey', value: 'invalid'}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const versionJsonWithDash = JSON.stringify({ | ||
d: { | ||
results: [ | ||
{ NormalizedVersion: '1.2-beta' } | ||
] | ||
} | ||
}); | ||
const versionJsonFirstCharZero = JSON.stringify({ | ||
d: { | ||
results: [ | ||
{ NormalizedVersion: '0.35' } | ||
] | ||
} | ||
}); | ||
const versionJsonFirstCharNotZero = JSON.stringify({ | ||
d: { | ||
results: [ | ||
{ NormalizedVersion: '1.2.7' } | ||
] | ||
} | ||
}); | ||
|
||
module.exports = { | ||
versionJsonWithDash, | ||
versionJsonFirstCharZero, | ||
versionJsonFirstCharNotZero | ||
}; |
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.
Few lines below there is a try-catch block. Catch block does not have tests. But in my opinion try-catch is unnecessary and can be removed. What do you think about it?
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.
yeah the
JSON.parse()
error is caught ingetNugetPackage()
so I've removed the others