forked from diegohaz/rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
196 lines (174 loc) · 5.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
var Promise = require('bluebird');
var path = require('path');
var fs = require('fs-extra');
var spawnCommand = require('yeoman-generator/lib/actions/spawn_command').spawnCommand;
var helpers = require('yeoman-test');
var authServices = ['facebook', 'github', 'google'];
function install(answers, done, generateApis) {
return helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts(answers)
.toPromise()
.then(function (dir) {
var promise = Promise.resolve(dir);
if (generateApis) {
console.log('Generating APIs...');
promise = defaultApi(dir).then(function (dir) {
return apiWithDifferentEndpointName(dir);
}).then(function (dir) {
return apiWithNoMethods(dir);
}).then(function (dir) {
return apiWithAllMasterMethods(dir);
}).then(function (dir) {
return apiWithAllAdminMethods(dir);
}).then(function (dir) {
return apiWithAllUserMethods(dir);
}).then(function (dir) {
return apiWithDifferentUserField(dir);
}).then(function (dir) {
return apiWithOnlyPostUserMethod(dir);
}).then(function (dir) {
return apiWithoutModel(dir);
}).then(function (dir) {
return apiWithModelFields(dir);
}).then(function (dir) {
return apiWithUserModelField(dir);
});
}
promise.then(function (dir) {
console.log('Copying node_modules folder...');
fs.ensureSymlinkSync(path.join(__dirname, '../node_modules'), path.join(dir, 'node_modules'));
spawnCommand('npm', ['run', 'lint']).on('exit', function (err) {
if (err) {
return done(err);
}
if (process.env.CI) {
spawnCommand('npm', ['test', '--', '-i', '--coverage']).on('exit', done);
} else {
spawnCommand('npm', ['test']).on('exit', done);
}
});
}).catch(function (err) {
console.log(err);
done(err);
});
});
}
function defaultApi(dir) {
return api({
kebab: 'default-api'
}, dir);
}
function apiWithDifferentEndpointName(dir) {
return api({
kebab: 'different-endpoint',
kebabs: 'tests'
}, dir);
}
function apiWithNoMethods(dir) {
return api({
kebab: 'no-method',
methods: []
}, dir);
}
function apiWithAllMasterMethods(dir) {
return api({
kebab: 'all-master',
masterMethods: ['POST', 'GET LIST', 'GET ONE', 'PUT', 'DELETE']
}, dir);
}
function apiWithAllAdminMethods(dir) {
return api({
kebab: 'all-admin',
adminMethods: ['POST', 'GET LIST', 'GET ONE', 'PUT', 'DELETE']
}, dir);
}
function apiWithAllUserMethods(dir) {
return api({
kebab: 'all-user',
userMethods: ['POST', 'GET LIST', 'GET ONE', 'PUT', 'DELETE']
}, dir);
}
function apiWithDifferentUserField(dir) {
return api({
kebab: 'user-field',
userMethods: ['POST', 'PUT', 'DELETE'],
userField: 'author'
}, dir);
}
function apiWithOnlyPostUserMethod(dir) {
return api({
kebab: 'only-post-user',
userMethods: ['POST']
}, dir);
}
function apiWithoutModel(dir) {
return api({
kebab: 'no-model',
generateModel: false
}, dir);
}
function apiWithModelFields(dir) {
return api({
kebab: 'field',
modelFields: 'title, content'
}, dir);
}
function apiWithUserModelField(dir) {
return api({
kebab: 'user-model-field',
modelFields: 'user',
userMethods: ['POST']
}, dir);
}
function api(answers, dir) {
return helpers.run(path.join(__dirname, '../generators/api'))
.inTmpDir(function (tmpDir) {
fs.copySync(dir, tmpDir);
})
.withPrompts(answers)
.toPromise();
}
describe('generator-rest', function () {
describe('default install', function () {
before(function (done) {
install({}, done, true);
});
it('should install and pass tests', function () {});
});
describe('install with password reset option', function () {
before(function (done) {
install({
https: true,
passwordReset: true
}, done);
});
it('should install and pass tests', function () {});
});
describe('install with different src and api directories', function () {
before(function (done) {
install({srcDir: 'server', apiDir: 'endpoints'}, done, true);
});
it('should install and pass tests', function () {});
});
authServices.forEach(function (service) {
describe('install with ' service ' auth method', function () {
before(function (done) {
install({authMethods: [service]}, done);
});
it('should install and pass tests', function () {});
});
});
describe('install with all auth methods', function () {
before(function (done) {
install({authMethods: ['password'].concat(authServices)}, done);
});
it('should install and pass tests', function () {});
});
describe('install without auth API', function () {
before(function (done) {
install({generateAuthApi: false}, done, true);
});
it('should install and pass tests', function () {});
});
});