Skip to content

Commit

Permalink
test: GambitManager
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Sep 17, 2023
1 parent de93c96 commit 3652ebf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions framework/core/js/tests/unit/common/GambitManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import GambitManager from '../../../src/common/GambitManager';

const gambits = new GambitManager();

test('gambits are converted to filters', function () {
expect(gambits.apply('discussions', { q: 'lorem created:2023-07-07 is:hidden author:behz' })).toStrictEqual({
q: 'lorem',
created: '2023-07-07',
hidden: true,
author: ['behz'],
});
});

test('gambits are negated when prefixed with a dash', function () {
expect(gambits.apply('discussions', { q: 'lorem -created:2023-07-07 -is:hidden -author:behz' })).toStrictEqual({
q: 'lorem',
'-created': '2023-07-07',
'-hidden': true,
'-author': ['behz'],
});
});

test('gambits are only applied for the correct resource type', function () {
expect(gambits.apply('users', { q: 'lorem created:2023-07-07 is:hidden author:behz email:behz@machine.local' })).toStrictEqual({
q: 'lorem created:2023-07-07 is:hidden author:behz',
email: 'behz@machine.local',
});
expect(gambits.apply('discussions', { q: 'lorem created:2023-07-07 is:hidden -author:behz email:behz@machine.local' })).toStrictEqual({
q: 'lorem email:behz@machine.local',
created: '2023-07-07',
hidden: true,
'-author': ['behz'],
});
});

0 comments on commit 3652ebf

Please sign in to comment.