This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a74ab3
commit 0c15e77
Showing
6 changed files
with
134 additions
and
13 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
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
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
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
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,106 @@ | ||
const domains = require('../lib/domains') | ||
|
||
describe('for a new domain', () => { | ||
let ask = jest.fn() | ||
let context = { | ||
prompt: { | ||
ask | ||
}, | ||
filesystem: { | ||
list: jest.fn() | ||
}, | ||
parameters: { | ||
options: {} | ||
} | ||
} | ||
beforeAll(() => { | ||
ask.mockReturnValueOnce(Promise.resolve({ domain: '(Create New)' })) | ||
}) | ||
|
||
it('returns an empty string', async () => { | ||
const path = await domains.getDomainPath('foo', context) | ||
expect(path).toEqual('') | ||
}) | ||
}) | ||
|
||
describe('for an existing domain', () => { | ||
let ask = jest.fn() | ||
let context = { | ||
prompt: { | ||
ask | ||
}, | ||
filesystem: { | ||
list: () => ['users'] | ||
}, | ||
parameters: { | ||
options: {} | ||
} | ||
} | ||
beforeEach(() => { | ||
ask.mockReturnValueOnce(Promise.resolve({ domain: 'users' })) | ||
}) | ||
|
||
it('asks the user to choose from available domains', async () => { | ||
await domains.getDomainPath('foo', context) | ||
expect(ask.mock.calls[0][0]).toEqual({ | ||
name: 'domain', | ||
type: 'list', | ||
message: 'Add this to which domain?', | ||
choices: ['(Create New)', 'users'] | ||
}) | ||
}) | ||
|
||
it('returns the selected path', async () => { | ||
const path = await domains.getDomainPath('foo', context) | ||
expect(path).toEqual('users/') | ||
}) | ||
}) | ||
|
||
describe('when a folder option is passed', () => { | ||
let ask = jest.fn() | ||
let context = { | ||
prompt: { | ||
ask | ||
}, | ||
filesystem: { | ||
list: () => ['users'] | ||
}, | ||
parameters: { | ||
options: { | ||
folder: 'bar' | ||
} | ||
} | ||
} | ||
|
||
it('does not prompt the user', async () => { | ||
await domains.getDomainPath('foo', context) | ||
expect(ask.mock.calls.length).toEqual(0) | ||
}) | ||
|
||
it('returns the specified path', async () => { | ||
const path = await domains.getDomainPath('foo', context) | ||
expect(path).toEqual('bar/') | ||
}) | ||
}) | ||
|
||
describe('when folder option matches the base directory', () => { | ||
let ask = jest.fn() | ||
let context = { | ||
prompt: { | ||
ask | ||
}, | ||
filesystem: { | ||
list: () => ['users'] | ||
}, | ||
parameters: { | ||
options: { | ||
folder: 'models' | ||
} | ||
} | ||
} | ||
|
||
it('returns an empty string (same as new domain)', async () => { | ||
const path = await domains.getDomainPath('models', context) | ||
expect(path).toEqual('') | ||
}) | ||
}) |
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