mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
allow [chromewebstore] size to contain decimal point (#10812)
* allow [chromewebstore] size to contain decimal point * Update services/chrome-web-store/chrome-web-store-size.service.js Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com> * Update services/chrome-web-store/chrome-web-store-size.spec.js Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com> * prettier --------- Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
This commit is contained in:
parent
2c089f7ba6
commit
49bcb52173
@ -22,8 +22,8 @@ export default class ChromeWebStoreSize extends BaseChromeWebStoreService {
|
||||
color: 'blue',
|
||||
}
|
||||
|
||||
transform(sizeStr) {
|
||||
const match = sizeStr.match(/^(\d+)([a-zA-Z]+)$/)
|
||||
static transform(sizeStr) {
|
||||
const match = sizeStr.match(/^(\d+(?:\.\d+)?)([a-zA-Z]+)$/)
|
||||
if (!match) {
|
||||
throw new InvalidResponse({
|
||||
prettyMessage: 'size does not match expected format',
|
||||
@ -41,6 +41,6 @@ export default class ChromeWebStoreSize extends BaseChromeWebStoreService {
|
||||
throw new NotFound({ prettyMessage: 'not found' })
|
||||
}
|
||||
|
||||
return { message: this.transform(size) }
|
||||
return { message: this.constructor.transform(size) }
|
||||
}
|
||||
}
|
||||
|
28
services/chrome-web-store/chrome-web-store-size.spec.js
Normal file
28
services/chrome-web-store/chrome-web-store-size.spec.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { expect } from 'chai'
|
||||
import { test, given } from 'sazerac'
|
||||
import { InvalidResponse } from '../index.js'
|
||||
import ChromeWebStoreSize from './chrome-web-store-size.service.js'
|
||||
|
||||
describe('transform function', function () {
|
||||
it('formats size correctly', function () {
|
||||
test(ChromeWebStoreSize.transform, () => {
|
||||
given('0.55KiB').expect('0.55 KiB')
|
||||
given('19.86KiB').expect('19.86 KiB')
|
||||
given('432KiB').expect('432 KiB')
|
||||
})
|
||||
})
|
||||
|
||||
it('throws when the format is unexpected', function () {
|
||||
expect(() => ChromeWebStoreSize.transform('432 KiB')).to.throw(
|
||||
InvalidResponse,
|
||||
)
|
||||
expect(() => ChromeWebStoreSize.transform('432')).to.throw(InvalidResponse)
|
||||
expect(() => ChromeWebStoreSize.transform('KiB')).to.throw(InvalidResponse)
|
||||
expect(() => ChromeWebStoreSize.transform('foobar')).to.throw(
|
||||
InvalidResponse,
|
||||
)
|
||||
expect(() => ChromeWebStoreSize.transform('4.4.4 KiB')).to.throw(
|
||||
InvalidResponse,
|
||||
)
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user