Skip to content

Commit

Permalink
Add tests for the validate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacroldan committed Sep 20, 2024
1 parent 73aa5cd commit 6797664
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/app/src/cli/services/init/validate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {validateTemplateValue, validateFlavorValue} from './validate.js'
import {describe, expect, test} from 'vitest'
import {AbortError} from '@shopify/cli-kit/node/error'

describe('validateTemplateValue', () => {
test('should not throw an error for undefined template', () => {
expect(() => validateTemplateValue(undefined)).not.toThrow()
})

test('should not throw an error for valid GitHub URL', () => {
expect(() => validateTemplateValue('https://github.com/Shopify/example')).not.toThrow()
})

test('should throw an AbortError for non-GitHub URL', () => {
expect(() => validateTemplateValue('https://gitlab.com/example')).toThrow(AbortError)
})

test('should not throw an error for valid predefined template', () => {
expect(() => validateTemplateValue('node')).not.toThrow()
})

test('should throw an AbortError for invalid template', () => {
expect(() => validateTemplateValue('invalid-template')).toThrow(AbortError)
})
})

describe('validateFlavorValue', () => {
test('should not throw an error when both template and flavor are undefined', () => {
expect(() => validateFlavorValue(undefined, undefined)).not.toThrow()
})

test('should throw an AbortError when flavor is provided without template', () => {
expect(() => validateFlavorValue(undefined, 'some-flavor')).toThrow(AbortError)
})

test('should not throw an error when template is provided without flavor', () => {
expect(() => validateFlavorValue('node', undefined)).not.toThrow()
})

test('should throw an AbortError when flavor is provided for custom template', () => {
expect(() => validateFlavorValue('https://github.com/custom/template', 'some-flavor')).toThrow(AbortError)
})

test('should throw an AbortError when template does not support flavors', () => {
expect(() => validateFlavorValue('ruby', 'some-flavor')).toThrow(AbortError)
})

test('should throw an AbortError for invalid flavor option', () => {
expect(() => validateFlavorValue('remix', 'invalid-flavor')).toThrow(AbortError)
})

test('should not throw an error for valid template and flavor combination', () => {
expect(() => validateFlavorValue('remix', 'javascript')).not.toThrow()
})
})

0 comments on commit 6797664

Please sign in to comment.