Skip to content

Commit

Permalink
🆕 workflows fixture object
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Aug 25, 2016
1 parent 9de2a95 commit 950f025
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
31 changes: 31 additions & 0 deletions tests/fixtures/workflows/all-flows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Mock of all workflows after yaml files imported
* @type {Array}
*/
module.exports = [
{
'name': 'Editor Approve',
'id': 'editor-approve',
'steps': [
{
'name': 'Send to Legal',
},
{
'name': 'Send to Editor',
},
{
'name': 'Publish',
},
],
},
{
'name': 'Self Publish',
'id': 'self-publish',
'steps': [
{
'name': 'Publish',
'self': true,
},
],
},
];
50 changes: 6 additions & 44 deletions tests/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
import content from 'punchcard-content-types';

import workflows from '../lib/workflows';
import allFlows from './fixtures/workflows/all-flows';

const revision = {
audit: '',
Expand All @@ -30,16 +31,6 @@ const request = {
},
};

const workflow = {
name: 'Editor Approve',
id: 'editor-approve',
steps: [
{ name: 'Send to Legal' },
{ name: 'Send to Editor' },
{ name: 'Publish' },
],
};

test('Workflow functions', t => {
t.is(typeof workflows.audits, 'function', '`audits` exists and is a function');
t.is(typeof workflows.utils.check, 'function', '`check` exists and is a function');
Expand Down Expand Up @@ -262,7 +253,7 @@ test('create an audit entry with variables', t => {
// Workflows - audits
//////////////////////////////
test('Audit created from approval submission', t => {
const audits = workflows.audits(revision, workflow, request);
const audits = workflows.audits(revision, allFlows[0], request);

t.is(typeof audits.audit, 'object', 'Audit should be an object');
t.true(Array.isArray(audits.audit.entries), 'Entries should be an array');
Expand All @@ -279,7 +270,7 @@ test('Audit created from approval submission', t => {
test('Audit created from rejection', t => {
const req = (JSON.parse(JSON.stringify(request)));
req.body = rejectedBody;
const audits = workflows.audits(revision, workflow, req);
const audits = workflows.audits(revision, allFlows[0], req);

t.is(typeof audits.audit, 'object', 'Audit should be an object');
t.true(Array.isArray(audits.audit.entries), 'Entries should be an array');
Expand All @@ -296,7 +287,7 @@ test('Audit created from rejection', t => {
test('Audit on content with one approval', t => {
const rev = (JSON.parse(JSON.stringify(revision)));
rev.approval = 1;
const audits = workflows.audits(rev, workflow, request);
const audits = workflows.audits(rev, allFlows[0], request);

t.is(typeof audits.audit, 'object', 'Audit should be an object');
t.true(Array.isArray(audits.audit.entries), 'Entries should be an array');
Expand All @@ -316,22 +307,6 @@ test('workflows in type', t => {
workflow: 'editor-approve',
};

const allFlows = [
{
'name': 'Editor Approve',
'id': 'editor-approve',
'steps': [
{
'name': 'Publish',
'self': true,
},
{
'name': 'Editor Approval',
},
],
},
];

const globalConfig = {
content: {
base: '/',
Expand All @@ -344,19 +319,6 @@ test('workflows in type', t => {
},
};

const expected = {
name: 'Editor Approve',
id: 'editor-approve',
steps: [
{
name: 'Publish',
self: true,
},
{
name: 'Editor Approval',
},
],
};
const req = {
params: {
type: 'services',
Expand All @@ -367,7 +329,7 @@ test('workflows in type', t => {
const wf = workflows.workflow(type, allFlows, globalConfig, req);

// get type workflow
t.is(JSON.stringify(wf), JSON.stringify(expected), 'Grabs an existing workflow');
t.is(JSON.stringify(wf), JSON.stringify(allFlows[0]), 'Grabs an existing workflow');

// bad workflow in type
const badtype = (JSON.parse(JSON.stringify(type)));
Expand All @@ -380,5 +342,5 @@ test('workflows in type', t => {
noflow.workflow = '';
const nopeflow = workflows.workflow(noflow, allFlows, globalConfig, req);

t.is(nopeflow, false, 'Returns false on workflow missing from global flows');
t.is(nopeflow, allFlows[1], 'Returns false on workflow missing from global flows');
});

0 comments on commit 950f025

Please sign in to comment.