Skip to content

Commit

Permalink
allow [chromewebstore] size to contain decimal point (#10812)
Browse files Browse the repository at this point in the history
* allow [chromewebstore] size to contain decimal point

* Update services/chrome-web-store/chrome-web-store-size.service.js

Co-authored-by: jNullj <[email protected]>

* Update services/chrome-web-store/chrome-web-store-size.spec.js

Co-authored-by: jNullj <[email protected]>

* prettier

---------

Co-authored-by: jNullj <[email protected]>
  • Loading branch information
chris48s and jNullj authored Jan 18, 2025
1 parent 2c089f7 commit 49bcb52
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions services/chrome-web-store/chrome-web-store-size.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 changes: 28 additions & 0 deletions services/chrome-web-store/chrome-web-store-size.spec.js
Original file line number Diff line number Diff line change
@@ -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,
)
})
})

0 comments on commit 49bcb52

Please sign in to comment.