|
3 | 3 | var _ = require('lodash');
|
4 | 4 | var async = require('async');
|
5 | 5 |
|
6 |
| - module.exports = function () { |
| 6 | +module.exports = function () { |
7 | 7 |
|
8 |
| - var seneca = this; |
| 8 | + var seneca = this; |
9 | 9 |
|
10 |
| - var plugin = 'test-user-data'; |
| 10 | + var plugin = 'test-user-data'; |
11 | 11 |
|
12 |
| - seneca.add({role: plugin, cmd: 'insert', entity: 'user'}, function (args, done) { |
| 12 | + seneca.add({role: plugin, cmd: 'insert', entity: 'user'}, function (args, done) { |
13 | 13 |
|
14 |
| - async.waterfall([ |
15 |
| - createIndependants, |
16 |
| - createDependantsChildren |
17 |
| - ], function (err, users) { |
18 |
| - return done(null); |
19 |
| - }); |
| 14 | + async.waterfall([ |
| 15 | + createIndependants, |
| 16 | + createDependantsChildren |
| 17 | + ], function (err, users) { |
| 18 | + return done(null); |
| 19 | + }); |
20 | 20 |
|
21 |
| - function createIndependants (wfCb) { |
22 |
| - var users = require('../fixtures/e2e/users.json'); |
23 |
| - async.eachSeries(users, function (user, cb) { |
24 |
| - seneca.act(user, {role: 'cd-users', cmd: 'register'}, function (err, response) { |
25 |
| - if (err) return done(err); |
26 |
| - if (response.ok === false) { |
27 |
| - console.error('insert failed: ', response); |
28 |
| - return cb(response); |
29 |
| - } |
30 |
| - return cb(err, response); |
31 |
| - }); |
32 |
| - }, wfCb); |
33 |
| - } |
34 |
| - |
35 |
| - function createDependantsChildren (wfCb) { |
36 |
| - var children = require('../fixtures/e2e/children.json'); |
37 |
| - async.eachSeries(children, function (child, cb) { |
38 |
| - function getParent (wfCb) { |
39 |
| - seneca.act({role: 'cd-users', cmd: 'list', query: {email: child.parentEmail}}, function (err, parents) { |
40 |
| - if (err) return done(err); |
41 |
| - return wfCb(null, parents[0]); |
42 |
| - }); |
43 |
| - } |
44 |
| - |
45 |
| - function saveChild (parent, wfCb) { |
46 |
| - child.parents = [parent.userId]; |
47 |
| - seneca.act({role: 'cd-profiles', cmd: 'save-youth-profile', profile: child.data, user: parent}, function (err, savedChild) { |
48 |
| - if (err) return wfCb(err); |
49 |
| - if (savedChild.ok === false) { |
50 |
| - console.error('insert failed: ', savedChild); |
51 |
| - return wfCb(savedChild); |
52 |
| - } |
53 |
| - return wfCb(err, savedChild); |
54 |
| - }); |
55 |
| - } |
56 |
| - |
57 |
| - async.waterfall([ |
58 |
| - getParent, |
59 |
| - saveChild |
60 |
| - ], cb); |
61 |
| - |
62 |
| - }, function (err, data) { |
63 |
| - return wfCb(); |
64 |
| - }); |
65 |
| - |
66 |
| - } |
67 |
| - |
68 |
| - }); |
69 |
| - |
70 |
| - seneca.add({role: plugin, cmd: 'insert', entity: 'agreement'}, function (args, done) { |
71 |
| - var users = require('../fixtures/e2e/users.json'); |
72 |
| - var champs = _.filter(users, function (user) { |
73 |
| - return user.user.email.indexOf('champion') > -1; |
74 |
| - }); |
75 |
| - async.eachSeries(champs, function (champ, sCb) { |
76 |
| - async.waterfall([ |
77 |
| - getUser, |
78 |
| - saveAgreement |
79 |
| - ], sCb); |
80 |
| - |
81 |
| - function getUser (wfCb) { |
82 |
| - seneca.act({role: 'cd-users', cmd: 'list', query: {email: champ.user.email}}, function (err, champs) { |
| 21 | + function createIndependants (wfCb) { |
| 22 | + var users = require('../fixtures/e2e/users.json'); |
| 23 | + async.eachSeries(users, function (user, cb) { |
| 24 | + seneca.act(user, {role: 'cd-users', cmd: 'register'}, function (err, response) { |
83 | 25 | if (err) return done(err);
|
84 |
| - return wfCb(null, champs[0]); |
| 26 | + if (response.ok === false) { |
| 27 | + console.error('insert failed: ', response); |
| 28 | + return cb(response); |
| 29 | + } |
| 30 | + return cb(err, response); |
85 | 31 | });
|
86 |
| - } |
87 |
| - |
88 |
| - function saveAgreement (champ, wfCb) { |
89 |
| - var payload = { |
90 |
| - fullName: champ.name, |
91 |
| - userId: champ.id |
92 |
| - }; |
93 |
| - seneca.act({role: 'cd-agreements', cmd: 'save', agreement: payload}, function (err, agreement) { |
| 32 | + }, wfCb); |
| 33 | + } |
| 34 | + |
| 35 | + function createDependantsChildren (wfCb) { |
| 36 | + var children = require('../fixtures/e2e/children.json'); |
| 37 | + async.eachSeries(children, function (child, cb) { |
| 38 | + function getParent (wfCb) { |
| 39 | + seneca.act({role: 'cd-users', cmd: 'list', query: {email: child.parentEmail}}, function (err, parents) { |
94 | 40 | if (err) return done(err);
|
95 |
| - return wfCb(null, agreement); |
96 |
| - }); |
97 |
| - } |
98 |
| - }, done); |
99 |
| - }); |
100 |
| - |
101 |
| - return { |
102 |
| - name: plugin |
103 |
| - }; |
104 |
| - }; |
| 41 | + return wfCb(null, parents[0]); |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + function saveChild (parent, wfCb) { |
| 46 | + child.parents = [parent.userId]; |
| 47 | + seneca.act({role: 'cd-profiles', cmd: 'save-youth-profile', profile: child.data, user: parent}, function (err, savedChild) { |
| 48 | + if (err) return wfCb(err); |
| 49 | + if (savedChild.ok === false) { |
| 50 | + console.error('insert failed: ', savedChild); |
| 51 | + return wfCb(savedChild); |
| 52 | + } |
| 53 | + return wfCb(err, savedChild); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + async.waterfall([ |
| 58 | + getParent, |
| 59 | + saveChild |
| 60 | + ], cb); |
| 61 | + |
| 62 | + }, function (err, data) { |
| 63 | + return wfCb(); |
| 64 | + }); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + }); |
| 69 | + |
| 70 | + seneca.add({role: plugin, cmd: 'insert', entity: 'agreement'}, function (args, done) { |
| 71 | + var users = require('../fixtures/e2e/users.json'); |
| 72 | + var champs = _.filter(users, function (user) { |
| 73 | + return user.user.email.indexOf('champion') > -1; |
| 74 | + }); |
| 75 | + async.eachSeries(champs, function (champ, sCb) { |
| 76 | + async.waterfall([ |
| 77 | + getUser, |
| 78 | + saveAgreement |
| 79 | + ], sCb); |
| 80 | + |
| 81 | + function getUser (wfCb) { |
| 82 | + seneca.act({role: 'cd-users', cmd: 'list', query: {email: champ.user.email}}, function (err, champs) { |
| 83 | + if (err) return done(err); |
| 84 | + return wfCb(null, champs[0]); |
| 85 | + }); |
| 86 | + } |
| 87 | + |
| 88 | + function saveAgreement (champ, wfCb) { |
| 89 | + var payload = { |
| 90 | + fullName: champ.name, |
| 91 | + userId: champ.id |
| 92 | + }; |
| 93 | + seneca.act({role: 'cd-agreements', cmd: 'save', agreement: payload}, function (err, agreement) { |
| 94 | + if (err) return done(err); |
| 95 | + return wfCb(null, agreement); |
| 96 | + }); |
| 97 | + } |
| 98 | + }, done); |
| 99 | + }); |
| 100 | + |
| 101 | + return { |
| 102 | + name: plugin |
| 103 | + }; |
| 104 | +}; |
0 commit comments