Jest for server

- Introduced the Jest testing framework into our server side code so
plugins can now have tests that run
This commit is contained in:
Wyatt Johnson
2018-04-11 19:02:38 -06:00
parent 7f9503d6aa
commit 86385e0d86
21 changed files with 774 additions and 772 deletions
+4 -16
View File
@@ -239,26 +239,14 @@ function getReactionConfig(reaction) {
hooks: {
Action: {
__resolveType: {
post({ action_type }) {
switch (action_type) {
case REACTION:
return `${Reaction}Action`;
default:
return undefined;
}
},
post: ({ action_type }) =>
action_type === REACTION ? `${Reaction}Action` : undefined,
},
},
ActionSummary: {
__resolveType: {
post({ action_type }) {
switch (action_type) {
case REACTION:
return `${Reaction}ActionSummary`;
default:
return undefined;
}
},
post: ({ action_type = '' } = {}) =>
action_type === REACTION ? `${Reaction}ActionSummary` : undefined,
},
},
},
@@ -0,0 +1,51 @@
const getReactionConfig = require('./getReactionConfig');
describe('plugins-api', () => {
describe('getReactionConfig', () => {
let config;
beforeEach(() => {
config = getReactionConfig('heart');
});
describe('context', () => {
it('provides a sort function', () => {
expect(config.context.Sort).toBeInstanceOf(Function);
const sort = config.context.Sort();
expect(sort.Comments).toHaveProperty('hearts');
});
});
describe('hooks', () => {
it('handles the __resolveType properly', () => {
expect(config.hooks.ActionSummary.__resolveType).toHaveProperty('post');
expect(config.hooks.ActionSummary.__resolveType.post).toBeInstanceOf(
Function
);
expect(
config.hooks.ActionSummary.__resolveType.post({})
).toBeUndefined();
expect(
config.hooks.ActionSummary.__resolveType.post({ action_type: 'LOVE' })
).toBeUndefined();
expect(
config.hooks.ActionSummary.__resolveType.post({
action_type: 'HEART',
})
).toEqual('HeartActionSummary');
});
it('handles the __resolveType properly', () => {
expect(config.hooks.Action.__resolveType).toHaveProperty('post');
expect(config.hooks.Action.__resolveType.post).toBeInstanceOf(Function);
expect(config.hooks.Action.__resolveType.post({})).toBeUndefined();
expect(
config.hooks.Action.__resolveType.post({ action_type: 'LOVE' })
).toBeUndefined();
expect(
config.hooks.Action.__resolveType.post({
action_type: 'HEART',
})
).toEqual('HeartAction');
});
});
});
});