Skip to content

Commit

Permalink
service tests for packagist-dependency-version.service.js are in prog…
Browse files Browse the repository at this point in the history
…ress
  • Loading branch information
PaulaBarszcz committed Sep 2, 2022
1 parent 6fe762e commit 55f50ce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions services/packagist/packagist-dependency-version.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { isComposerVersion } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('gets the package version of symfony')
.get('/symfony/symfony.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({ label: 'twig/twig', message: isComposerVersion })

t.create('gets the package version of symfony 5.2.3')
.get('/symfony/symfony/v5.2.3.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({ label: 'twig/twig', message: isComposerVersion })

t.create('package with no requirements')
.get('/bpampuch/pdfmake.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({
label: 'dependency version',
message: 'version requirement not found',
})

t.create('package with no twig/twig version requirement')
.get(
'/raulfraile/ladybug-theme-modern.json?dependencyVendor=twig&dependencyRepo=twig'
)
.expectBadge({
label: 'dependency version',
message: 'version requirement not found',
})

t.create('invalid package name')
.get('/frodo/is-not-a-package.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({ label: 'dependency version', message: 'not found' })

t.create('invalid version')
.get(
'/symfony/symfony/invalid.json?dependencyVendor=twig&dependencyRepo=twig'
)
.expectBadge({ label: 'dependency version', message: 'invalid version' })

t.create('custom server')
.get(
'/symfony/symfony.json?server=https%3A%2F%2Fpackagist.org&dependencyVendor=twig&dependencyRepo=twig'
)
.expectBadge({ label: 'twig/twig', message: isComposerVersion })

t.create('invalid custom server')
.get(
'/symfony/symfony.json?server=https%3A%2F%2Fpackagist.com&dependencyVendor=twig&dependencyRepo=twig'
)
.expectBadge({ label: 'dependency version', message: 'not found' })
2 changes: 1 addition & 1 deletion services/test-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch = withRegex(
// https://getcomposer.org/doc/04-schema.md#package-links
// https://getcomposer.org/doc/04-schema.md#minimum-stability
const isComposerVersion = withRegex(
/^\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?((\s*\|\|)?\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?)*\s*$/
/^\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?((\s*\|*)?\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?)*\s*$/
)

// Regex for validate php-version.versionReduction()
Expand Down

0 comments on commit 55f50ce

Please sign in to comment.