This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow ApplyOptions to take a function (#24)
Co-authored-by: Jeroen Claassens <[email protected]>
- Loading branch information
1 parent
2966580
commit cbcabdc
Showing
10 changed files
with
279 additions
and
163 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
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,53 @@ | ||
import { Cache } from '@klasa/cache'; | ||
import { client, MockCommandStore } from '@mocks/MockInstances'; | ||
import { ApplyOptions } from '@src/core-decorators'; | ||
import { CreateResolver } from '@src/starlight-decorators'; | ||
import { Command, CommandOptions, CustomUsageArgument } from 'klasa'; | ||
|
||
describe('CreateResolver Decorator', () => { | ||
const mockCommandStore = new MockCommandStore('name', client); | ||
const receivedResolvers = new Cache<string, CustomUsageArgument>([ | ||
[ | ||
'key', | ||
(arg, _possible, message, [action]) => { | ||
if (action === 'show' || arg) return arg || ''; | ||
throw message.language.get('COMMAND_CONF_NOKEY'); | ||
} | ||
] | ||
]); | ||
|
||
test('Applies Resolver to a command', () => { | ||
@CreateResolver('key', (arg, _possible, message, [action]) => { | ||
if (action === 'show' || arg) return arg || ''; | ||
throw message.language.get('COMMAND_CONF_NOKEY'); | ||
}) | ||
class TestCommand extends Command {} | ||
|
||
const instance = new TestCommand(mockCommandStore, __dirname, [__filename]); | ||
|
||
expect(instance.usage.customResolvers.firstValue).toEqual(expect.any(Function)); | ||
expect(instance.usage.customResolvers.firstKey).toEqual(receivedResolvers.firstKey); | ||
|
||
expect(instance.usage.customResolvers.size).toEqual(1); | ||
}); | ||
|
||
test('Is compatible with @ApplyOptions', () => { | ||
@ApplyOptions<CommandOptions>({ | ||
name: 'test', | ||
cooldown: 10 | ||
}) | ||
@CreateResolver('key', (arg, _possible, message, [action]) => { | ||
if (action === 'show' || arg) return arg || ''; | ||
throw message.language.get('COMMAND_CONF_NOKEY'); | ||
}) | ||
class TestCommand extends Command {} | ||
|
||
const instance = new TestCommand(mockCommandStore, __dirname, [__filename]); | ||
|
||
expect(instance.name).toEqual('test'); | ||
expect(instance.usage.customResolvers.firstValue).toEqual(expect.any(Function)); | ||
expect(instance.usage.customResolvers.firstKey).toEqual(receivedResolvers.firstKey); | ||
|
||
expect(instance.usage.customResolvers.size).toEqual(1); | ||
}); | ||
}); |
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
Oops, something went wrong.