-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add emoji and enum resolver tests (#361)
- Loading branch information
1 parent
18259a7
commit 990be5b
Showing
2 changed files
with
85 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,37 @@ | ||
import { Identifiers, Resolvers } from '../../src'; | ||
|
||
describe('Emoji resolver tests', () => { | ||
test('GIVEN an unicode emoji THEN returns emojiObject', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji('😄'); | ||
expect(resolvedEmoji.success).toBe(true); | ||
expect(resolvedEmoji.error).toBeUndefined(); | ||
expect(resolvedEmoji.value).toMatchObject({ id: null, name: '😄' }); | ||
}); | ||
test('GIVEN a string emoji THEN returns ArgumentEmojiError', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji(':smile:'); | ||
expect(resolvedEmoji.success).toBe(false); | ||
expect(resolvedEmoji.error).toBe(Identifiers.ArgumentEmojiError); | ||
}); | ||
test('GIVEN a string THEN returns ArgumentEmojiError', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji('foo'); | ||
expect(resolvedEmoji.success).toBe(false); | ||
expect(resolvedEmoji.error).toBe(Identifiers.ArgumentEmojiError); | ||
}); | ||
test('GIVEN a wrongly formatted string custom emoji THEN returns ArgumentEmojiError', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji('<custom:737141877803057244>'); | ||
expect(resolvedEmoji.success).toBe(false); | ||
expect(resolvedEmoji.error).toBe(Identifiers.ArgumentEmojiError); | ||
}); | ||
test('GIVEN a string custom emoji THEN returns emojiObject', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji('<:custom:737141877803057244>'); | ||
expect(resolvedEmoji.success).toBe(true); | ||
expect(resolvedEmoji.error).toBeUndefined(); | ||
expect(resolvedEmoji.value).toMatchObject({ id: '737141877803057244', name: 'custom' }); | ||
}); | ||
test('GIVEN a string custom animated emoji THEN returns emojiObject', () => { | ||
const resolvedEmoji = Resolvers.resolveEmoji('<a:custom:737141877803057244>'); | ||
expect(resolvedEmoji.success).toBe(true); | ||
expect(resolvedEmoji.error).toBeUndefined(); | ||
expect(resolvedEmoji.value).toMatchObject({ animated: true, id: '737141877803057244', name: 'custom' }); | ||
}); | ||
}); |
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,48 @@ | ||
import { Identifiers, Resolvers } from '../../src'; | ||
|
||
describe('Enum resolver tests', () => { | ||
test('GIVEN good lowercase enum from one option THEN returns string', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('foo', { enum: ['foo'] }); | ||
expect(resolvedEnum.success).toBe(true); | ||
expect(resolvedEnum.error).toBeUndefined(); | ||
expect(resolvedEnum.value).toBe('foo'); | ||
}); | ||
test('GIVEN good mixedcase enum from one option THEN returns string', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('FoO', { enum: ['FoO'] }); | ||
expect(resolvedEnum.success).toBe(true); | ||
expect(resolvedEnum.error).toBeUndefined(); | ||
expect(resolvedEnum.value).toBe('FoO'); | ||
}); | ||
test('GIVEN good enum from more options THEN returns string', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('foo', { enum: ['foo', 'bar', 'baz'] }); | ||
expect(resolvedEnum.success).toBe(true); | ||
expect(resolvedEnum.error).toBeUndefined(); | ||
expect(resolvedEnum.value).toBe('foo'); | ||
}); | ||
test('GIVEN good case insensitive enum from more options THEN returns string', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('FoO', { enum: ['FoO', 'foo', 'bar', 'baz'], caseInsensitive: false }); | ||
expect(resolvedEnum.success).toBe(true); | ||
expect(resolvedEnum.error).toBeUndefined(); | ||
expect(resolvedEnum.value).toBe('FoO'); | ||
}); | ||
test('GIVEN good enum from one option THEN returns ArgumentEnumError', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('foo', { enum: ['foo'] }); | ||
expect(resolvedEnum.success).toBe(true); | ||
expect(resolvedEnum.error).toBeUndefined(); | ||
}); | ||
test('GIVEN an empty enum array THEN returns ArgumentEnumEmptyError', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('foo'); | ||
expect(resolvedEnum.success).toBe(false); | ||
expect(resolvedEnum.error).toBe(Identifiers.ArgumentEnumEmptyError); | ||
}); | ||
test('GIVEN an enum not listed in the array THEN returns ArgumentEnumError', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('foo', { enum: ['bar', 'baz'] }); | ||
expect(resolvedEnum.success).toBe(false); | ||
expect(resolvedEnum.error).toBe(Identifiers.ArgumentEnumError); | ||
}); | ||
test('GIVEN an enum with wrong case THEN returns ArgumentEnumError', () => { | ||
const resolvedEnum = Resolvers.resolveEnum('FOO', { enum: ['bar', 'baz'], caseInsensitive: false }); | ||
expect(resolvedEnum.success).toBe(false); | ||
expect(resolvedEnum.error).toBe(Identifiers.ArgumentEnumError); | ||
}); | ||
}); |