-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the validate functions
- Loading branch information
1 parent
73aa5cd
commit 6797664
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |