-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'badges:master' into feat/9493/improve-auth-testing
- Loading branch information
Showing
9 changed files
with
164 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
45 changes: 8 additions & 37 deletions
45
services/chrome-web-store/chrome-web-store-price.service.js
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 |
---|---|---|
@@ -1,39 +1,10 @@ | ||
import { currencyFromCode } from '../text-formatters.js' | ||
import { NotFound, pathParams } from '../index.js' | ||
import BaseChromeWebStoreService from './chrome-web-store-base.js' | ||
import { deprecatedService } from '../index.js' | ||
|
||
export default class ChromeWebStorePrice extends BaseChromeWebStoreService { | ||
static category = 'funding' | ||
static route = { base: 'chrome-web-store/price', pattern: ':storeId' } | ||
const ChromeWebStorePrice = deprecatedService({ | ||
category: 'funding', | ||
route: { base: 'chrome-web-store/price', pattern: ':storeId' }, | ||
label: 'price', | ||
dateAdded: new Date('2024-02-18'), | ||
}) | ||
|
||
static openApi = { | ||
'/chrome-web-store/price/{storeId}': { | ||
get: { | ||
summary: 'Chrome Web Store Price', | ||
parameters: pathParams({ | ||
name: 'storeId', | ||
example: 'ogffaloegjglncjfehdfplabnoondfjo', | ||
}), | ||
}, | ||
}, | ||
} | ||
|
||
static defaultBadgeData = { label: 'price' } | ||
|
||
static render({ priceCurrency, price }) { | ||
return { | ||
message: `${currencyFromCode(priceCurrency) + price}`, | ||
color: 'brightgreen', | ||
} | ||
} | ||
|
||
async handle({ storeId }) { | ||
const chromeWebStore = await this.fetch({ storeId }) | ||
const priceCurrency = chromeWebStore.priceCurrency() | ||
const price = chromeWebStore.price() | ||
if (priceCurrency == null || price == null) { | ||
throw new NotFound({ prettyMessage: 'not found' }) | ||
} | ||
return this.constructor.render({ priceCurrency, price }) | ||
} | ||
} | ||
export default ChromeWebStorePrice |
28 changes: 10 additions & 18 deletions
28
services/chrome-web-store/chrome-web-store-price.tester.js
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 |
---|---|---|
@@ -1,20 +1,12 @@ | ||
import Joi from 'joi' | ||
import { createServiceTester } from '../tester.js' | ||
export const t = await createServiceTester() | ||
import { ServiceTester } from '../tester.js' | ||
|
||
t.create('Price') | ||
.get('/alhjnofcnnpeaphgeakdhkebafjcpeae.json') | ||
.expectBadge({ | ||
label: 'price', | ||
message: Joi.string().regex(/^\$\d+(.\d{1,2})?$/), | ||
}) | ||
export const t = new ServiceTester({ | ||
id: 'ChromeWebStorePrice', | ||
title: 'ChromeWebStorePrice', | ||
pathPrefix: '/chrome-web-store/price', | ||
}) | ||
|
||
t.create('Price (not found)') | ||
.get('/invalid-name-of-addon.json') | ||
.expectBadge({ label: 'price', message: 'not found' }) | ||
|
||
// Keep this "inaccessible" test, since this service does not use BaseService#_request. | ||
t.create('Price (inaccessible)') | ||
.get('/alhjnofcnnpeaphgeakdhkebafjcpeae.json') | ||
.networkOff() | ||
.expectBadge({ label: 'price', message: 'inaccessible' }) | ||
t.create('Price').get('/alhjnofcnnpeaphgeakdhkebafjcpeae.json').expectBadge({ | ||
label: 'price', | ||
message: 'no longer available', | ||
}) |
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
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,87 @@ | ||
import Joi from 'joi' | ||
import prettyBytes from 'pretty-bytes' | ||
import { pathParam, queryParam } from '../index.js' | ||
import { optionalNonNegativeInteger } from '../validators.js' | ||
import NpmBase, { packageNameDescription } from './npm-base.js' | ||
|
||
const schema = Joi.object({ | ||
dist: Joi.object({ | ||
unpackedSize: optionalNonNegativeInteger, | ||
}).required(), | ||
}).required() | ||
|
||
export default class NpmUnpackedSize extends NpmBase { | ||
static category = 'size' | ||
|
||
static route = { | ||
base: 'npm/unpacked-size', | ||
pattern: ':scope(@[^/]+)?/:packageName/:version*', | ||
} | ||
|
||
static openApi = { | ||
'/npm/unpacked-size/{packageName}': { | ||
get: { | ||
summary: 'NPM Unpacked Size', | ||
parameters: [ | ||
pathParam({ | ||
name: 'packageName', | ||
example: 'npm', | ||
description: packageNameDescription, | ||
}), | ||
queryParam({ | ||
name: 'registry_uri', | ||
example: 'https://registry.npmjs.com', | ||
}), | ||
], | ||
}, | ||
}, | ||
'/npm/unpacked-size/{packageName}/{version}': { | ||
get: { | ||
summary: 'NPM Unpacked Size (with version)', | ||
parameters: [ | ||
pathParam({ | ||
name: 'packageName', | ||
example: 'npm', | ||
description: packageNameDescription, | ||
}), | ||
pathParam({ | ||
name: 'version', | ||
example: '4.18.2', | ||
}), | ||
queryParam({ | ||
name: 'registry_uri', | ||
example: 'https://registry.npmjs.com', | ||
}), | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
static defaultBadgeData = { label: 'unpacked size' } | ||
|
||
async fetch({ registryUrl, packageName, version }) { | ||
return this._requestJson({ | ||
schema, | ||
url: `${registryUrl}/${packageName}/${version}`, | ||
}) | ||
} | ||
|
||
async handle( | ||
{ scope, packageName, version }, | ||
{ registry_uri: registryUrl = 'https://registry.npmjs.org' }, | ||
) { | ||
const packageNameWithScope = scope ? `${scope}/${packageName}` : packageName | ||
const { dist } = await this.fetch({ | ||
registryUrl, | ||
packageName: packageNameWithScope, | ||
version: version ?? 'latest', | ||
}) | ||
const { unpackedSize } = dist | ||
|
||
return { | ||
label: 'unpacked size', | ||
message: unpackedSize ? prettyBytes(unpackedSize) : 'unknown', | ||
color: unpackedSize ? 'blue' : 'lightgray', | ||
} | ||
} | ||
} |
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,28 @@ | ||
import { isFileSize } from '../test-validators.js' | ||
import { createServiceTester } from '../tester.js' | ||
|
||
export const t = await createServiceTester() | ||
|
||
t.create('Latest unpacked size') | ||
.get('/firereact.json') | ||
.expectBadge({ label: 'unpacked size', message: isFileSize }) | ||
|
||
t.create('Nonexistent unpacked size with version') | ||
.get('/express/4.16.0.json') | ||
.expectBadge({ label: 'unpacked size', message: 'unknown' }) | ||
|
||
t.create('Unpacked size with version') | ||
.get('/firereact/0.7.0.json') | ||
.expectBadge({ label: 'unpacked size', message: '147 kB' }) | ||
|
||
t.create('Unpacked size for scoped package') | ||
.get('/@testing-library/react.json') | ||
.expectBadge({ label: 'unpacked size', message: isFileSize }) | ||
|
||
t.create('Unpacked size for scoped package with version') | ||
.get('/@testing-library/react/14.2.1.json') | ||
.expectBadge({ label: 'unpacked size', message: '5.41 MB' }) | ||
|
||
t.create('Nonexistent unpacked size for scoped package with version') | ||
.get('/@cycle/rx-run/7.2.0.json') | ||
.expectBadge({ label: 'unpacked size', message: 'unknown' }) |
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
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