* improve stackexchange auth testing
Change auth tests to include all shields of the base class.
The code is formated to be used in more general cases and increases code reuseability.
* Remove dummy auth test
We already test all existing classes, no need for a dummy
* Add getBadgeExampleCall to test-helpers
Add getBadgeExampleCall to extract the first OpenAPI example then reformat it for service invoke function.
* Use getBadgeExampleCall in stackexchange-base tests
* Fix getBadgeExampleCall Errors
* Add testAuth to test-helpers
Add the testAuth function which tests auth of a service (badge) using a provided dummy response.
* Refactor stackexchange-base.spec.js to use testAuth from test-helpers
* Split stackexchange-base.spec into per service test file
* Add all auth methods to testAuth
Add all auth methods used to testAuth to be generic and used by all services.
Add helper functions to make testAuth more readable
* Handle non-default bearer and api headers
* Add discord.spec.js as first attempt for bearer auth
* Fix basic auth user
* Add dynamic authorizedOrigins
* Add header optional argument
* Add obs as basicAuth example
* Use apiHeaderKey and bearerHeaderKey function params
Use apiHeaderKey & bearerHeaderKey as function params rather then extracting them with regex from function strings.
Those options are now part of an options object param joined with the contentType that replaces header.
header was originaly added for setting content type of the reply, so it makes more sense to directly set the content type
* Remove old comment
* Allow any pass & user key for QueryStringAuth
Before this commit the QueryStringAuth would only work for the key of stackexchange.
This commit makes the testAuth function generic and allows passing user and pass keys.
* Add auth test for PepyDownloads
* Fix wrong header for jwt login
Might set wrong header for jwt login request.
This commit fixes that.
* Support multiple authOrigins in testAuth
Some services might have more then one authOrigin.
This commit makes sure we test for redundent authOrigins as well as support requests to them if needed.
* Add docker-automated auth test
* Fix JwtAuth testing by introducing mandatory jwtLoginEndpoint
Prior to this change, JwtAuth testing would lead to erros due to the absence of a specified login endpoint,
Nock would be dumplicated for both login and non login hosts and indicate a missing request.
This commit enforces the requirement for a new jwtLoginEndpoint argument when testing JwtAuth.
The argument seperates the endpoint nock scope from the behavior of the request nock.
* Fix type test in generateFakeConfig
* allow serviceData to override cacheSeconds with a longer value
* prevent [endpoint] json cacheSeconds property exceeding service default
* allow ShieldsRuntimeError to specify a cacheSeconds property
By default error responses use the cacheLength of
the service class throwing the error.
This allows error to tell the handling layer the maxAge
that should be set on the error badge response.
* add customExceptions param
This
1. allows us to specify custom properties to pass to the exception
constructor if we throw any of the standard got errors
e.g: `ETIMEDOUT`, `ECONNRESET`, etc
2. uses a custom `cacheSeconds` property (if set on the exception)
to set the response maxAge
* customExceptions --> systemErrors
* errorMessages --> httpErrors
I find having these in a consistent order makes the services much faster to read.
This is the order I’ve generally been using:
1. Category
2. Route
3. Examples
4. Rendering
5. Other helpers (`fetch()`, `transform()`)
6. `handle()`
This moves a few helpers from `lib/` to `services/`:
build-status.js
build-status.spec.js
color-formatters.js
color-formatters.spec.js
contributor-count.js
licenses.js
licenses.spec.js
php-version.js
php-version.spec.js
text-formatters.js
text-formatters.spec.js
version.js
version.spec.js
And one from `lib/` to `core/`:
unhandled-rejection.spec.js
The diff is long, but the changes are straightforward.
Ref #2832
This will definitely save time, and ensure more uniformity.
It moves the `createServiceTester()` calls to a different place from where I'd like them, though I'm happy to have them checked by the linter.
Closes#2701
Fixes#2876 with @paulmelnikow's suggestion
Moved imports of `ServiceTester` and `createServiceTester` to a separate file so that dev dependencies are not imported by service classes.
Continue to implement #2698:
- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
- Badge shows number of questions for a given library for the previous month (not current month because its in progress)
- Service works for not just the StackOverflow site but for other StackExchange sites also
Close#2378
* Fix URL pattern for StackExchange Questions and Reputation per #2418
Url patterns have been changed back to their older legacy format.
Tests now run properly with this URL in addition to the examples
showing up on local.
* Make changes per review comments. Also change "q" to "t" parameter to match legacy url for questions
Per part of issue #2378, convert StackExchange service to the newer
BaseJson class. Refactor also to seperate StackExchange reputation and
questions tag info into new StackExchange subservice files
as the legacy class contained both which may be difficult to keep track
of in the future as the service continues to grow.
More tests have been added to make sure other StackExchange sites besides
StackOverflow will still work with the new badge setup.
This is consistent with what we're pretty much already doing, and saves us from making the request during code review.
These were all autofixed and most of them seem easier to read. Some in the legacy services should be rewritten in more legible forms during refactor (ie using intermediate variables, or using request’s qs option). There are some in helper functions and elsewhere that should get rewritten separately. I don't want to change them in this PR because the changes will get lost in this diff, though we could identify them here and fix them before or just after.