@arc-fusion/cli
Version:
CLI for running Arc Fusion on your local machine
86 lines (69 loc) • 2.49 kB
JavaScript
import { describe, expect, test } from 'vitest'
import {
IS_GLOBAL,
LOCAL_SCRIPT_PATH,
PROJECT_ROOT,
REPO_NAME,
sanitizeDBName
} from './environment'
describe('IS_GLOBAL', () => {
test('should be true if not executed from node_modules', () => {
expect(IS_GLOBAL).toEqual(true)
})
})
describe('LOCAL_SCRIPT_PATH', () => {
test('should be undefined if not executed from node_modules', () => {
expect(LOCAL_SCRIPT_PATH).toBe(undefined)
})
})
describe('PROJECT_ROOT', () => {
test('should be the folder where the environment module is invoked', () => {
// This folder is wherever you have the repo checked out
// When the fusion CLI is invoked from a customer bundle, it will be the folder name.
expect(PROJECT_ROOT.endsWith('fusion-cli')).toBe(true)
})
})
describe('REPO_NAME', () => {
test('should be the folder name where the module is invoked', () => {
expect(REPO_NAME).toEqual('fusion-cli')
})
})
describe('sanitizeDBName', () => {
test('should disallow reserved MongoDB names', () => {
expect(sanitizeDBName('admin')).toEqual('localhost')
expect(sanitizeDBName('local')).toEqual('localhost')
expect(sanitizeDBName('config')).toEqual('localhost')
})
test('should remove whitespace from DB name', () => {
expect(sanitizeDBName('this folder name has spaces')).toEqual('thisfoldernamehasspaces')
})
test('should remove periods from DB name', () => {
expect(sanitizeDBName('t.e.s.t')).toEqual('test')
})
test('should remove commas from DB name', () => {
expect(sanitizeDBName('t,e,s,t')).toEqual('test')
})
test('should remove apostrophes from DB name', () => {
expect(sanitizeDBName('this_name_is_"special"')).toEqual(
'this_name_is_special'
)
})
test('should remove dollar signs from DB name', () => {
expect(sanitizeDBName('ke$ha')).toEqual('keha')
})
test('should remove asterisks from DB name', () => {
expect(sanitizeDBName('wild*card')).toEqual('wildcard')
})
test('should remove angle brackets from DB name', () => {
expect(sanitizeDBName('<html>')).toEqual('html')
})
test('should remove pipe symbols from DB name', () => {
expect(sanitizeDBName('|this|')).toEqual('this')
})
test('should remove colons from DB name', () => {
expect(sanitizeDBName('avengers:endgame')).toEqual('avengersendgame')
})
test('should remove question marks from DB name', () => {
expect(sanitizeDBName('test?')).toEqual('test')
})
})