From cff6cdcc336e2100fc06751002e84bac412a0f94 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 3 Feb 2026 20:30:54 +0000 Subject: [PATCH] test: reorganise npm unit tests Leftovers from when I moved the utils around. --- test/unit/app/utils/npm.spec.ts | 52 -------------------------- test/unit/app/utils/npm/common.spec.ts | 22 +++++++++++ test/unit/shared/utils/spdx.spec.ts | 8 +++- 3 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 test/unit/app/utils/npm.spec.ts create mode 100644 test/unit/app/utils/npm/common.spec.ts diff --git a/test/unit/app/utils/npm.spec.ts b/test/unit/app/utils/npm.spec.ts deleted file mode 100644 index f6bc417b0..000000000 --- a/test/unit/app/utils/npm.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { describe, expect, it } from 'vitest' - -import { buildScopeTeam } from '../../../../app/utils/npm/common' -import { validateScopeTeam } from '../../../../cli/src/npm-client' -import { getSpdxLicenseUrl } from '../../../../shared/utils/spdx' - -describe('getSpdxLicenseUrl', () => { - it('returns SPDX URL for valid license identifiers', () => { - expect(getSpdxLicenseUrl('MIT')).toBe('https://spdx.org/licenses/MIT.html') - expect(getSpdxLicenseUrl('ISC')).toBe('https://spdx.org/licenses/ISC.html') - expect(getSpdxLicenseUrl('Apache-2.0')).toBe('https://spdx.org/licenses/Apache-2.0.html') - expect(getSpdxLicenseUrl('GPL-3.0-only')).toBe('https://spdx.org/licenses/GPL-3.0-only.html') - expect(getSpdxLicenseUrl('BSD-2-Clause')).toBe('https://spdx.org/licenses/BSD-2-Clause.html') - expect(getSpdxLicenseUrl('GPL-3.0+')).toBe('https://spdx.org/licenses/GPL-3.0+.html') - }) - - it('trims whitespace from license identifiers', () => { - expect(getSpdxLicenseUrl(' MIT ')).toBe('https://spdx.org/licenses/MIT.html') - }) - - it('returns null for undefined or empty', () => { - expect(getSpdxLicenseUrl(undefined)).toBeNull() - expect(getSpdxLicenseUrl('')).toBeNull() - expect(getSpdxLicenseUrl(' ')).toBeNull() - }) - - it('returns null for invalid license identifiers', () => { - // Compound expressions are not in the SPDX list - expect(getSpdxLicenseUrl('MIT OR Apache-2.0')).toBeNull() - // Non-existent licenses - expect(getSpdxLicenseUrl('INVALID-LICENSE')).toBeNull() - expect(getSpdxLicenseUrl('Custom')).toBeNull() - }) -}) - -describe('buildScopeTeam', () => { - it('constructs scope:team with @ prefix', () => { - expect(buildScopeTeam('netlify', 'developers')).toBe('@netlify:developers') - expect(buildScopeTeam('nuxt', 'core')).toBe('@nuxt:core') - }) - - it('strips existing @ prefix from orgName', () => { - expect(buildScopeTeam('@netlify', 'developers')).toBe('@netlify:developers') - expect(buildScopeTeam('@nuxt', 'core')).toBe('@nuxt:core') - }) - - it('produces format accepted by validateScopeTeam', () => { - expect(() => validateScopeTeam(buildScopeTeam('netlify', 'developers'))).not.toThrow() - expect(() => validateScopeTeam(buildScopeTeam('nuxt', 'core'))).not.toThrow() - expect(() => validateScopeTeam(buildScopeTeam('my-org', 'my-team'))).not.toThrow() - }) -}) diff --git a/test/unit/app/utils/npm/common.spec.ts b/test/unit/app/utils/npm/common.spec.ts new file mode 100644 index 000000000..c750e83c7 --- /dev/null +++ b/test/unit/app/utils/npm/common.spec.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from 'vitest' + +import { buildScopeTeam } from '../../../../../app/utils/npm/common' +import { validateScopeTeam } from '../../../../../cli/src/npm-client' + +describe('buildScopeTeam', () => { + it('constructs scope:team with @ prefix', () => { + expect(buildScopeTeam('netlify', 'developers')).toBe('@netlify:developers') + expect(buildScopeTeam('nuxt', 'core')).toBe('@nuxt:core') + }) + + it('strips existing @ prefix from orgName', () => { + expect(buildScopeTeam('@netlify', 'developers')).toBe('@netlify:developers') + expect(buildScopeTeam('@nuxt', 'core')).toBe('@nuxt:core') + }) + + it('produces format accepted by validateScopeTeam', () => { + expect(() => validateScopeTeam(buildScopeTeam('netlify', 'developers'))).not.toThrow() + expect(() => validateScopeTeam(buildScopeTeam('nuxt', 'core'))).not.toThrow() + expect(() => validateScopeTeam(buildScopeTeam('my-org', 'my-team'))).not.toThrow() + }) +}) diff --git a/test/unit/shared/utils/spdx.spec.ts b/test/unit/shared/utils/spdx.spec.ts index 4d4e94493..05c3a5c6d 100644 --- a/test/unit/shared/utils/spdx.spec.ts +++ b/test/unit/shared/utils/spdx.spec.ts @@ -25,19 +25,25 @@ describe('spdx utilities', () => { }) describe('getSpdxLicenseUrl', () => { - it('returns URL for valid SPDX licenses', () => { + it('returns URL for valid license identifiers', () => { expect(getSpdxLicenseUrl('MIT')).toBe('https://spdx.org/licenses/MIT.html') + expect(getSpdxLicenseUrl('ISC')).toBe('https://spdx.org/licenses/ISC.html') expect(getSpdxLicenseUrl('Apache-2.0')).toBe('https://spdx.org/licenses/Apache-2.0.html') + expect(getSpdxLicenseUrl('GPL-3.0-only')).toBe('https://spdx.org/licenses/GPL-3.0-only.html') + expect(getSpdxLicenseUrl('BSD-2-Clause')).toBe('https://spdx.org/licenses/BSD-2-Clause.html') + expect(getSpdxLicenseUrl('GPL-3.0+')).toBe('https://spdx.org/licenses/GPL-3.0+.html') }) it('returns null for invalid licenses', () => { expect(getSpdxLicenseUrl('CustomLicense')).toBeNull() expect(getSpdxLicenseUrl('INVALID')).toBeNull() + expect(getSpdxLicenseUrl('MIT OR Apache-2.0')).toBeNull() }) it('returns null for undefined or empty', () => { expect(getSpdxLicenseUrl(undefined)).toBeNull() expect(getSpdxLicenseUrl('')).toBeNull() + expect(getSpdxLicenseUrl(' ')).toBeNull() }) it('trims whitespace', () => {