forked from appdevdesigns/appdev-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappdev_fixture.js
More file actions
108 lines (70 loc) · 2.97 KB
/
appdev_fixture.js
File metadata and controls
108 lines (70 loc) · 2.97 KB
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
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');
var $ = require('jquery');
var Util = require('./helpers/util_helper.js');
var assert = require('chai').assert;
describe('test appdev fixture :applicationName :resource :fieldList ',function(){
//Before the unit tests are executed, create the testing directory structure
before(function(done){
this.timeout(10000);
// run this command from the test/scratchArea/ directory
process.chdir(path.join(__dirname, 'scratchArea'));
// now run the command to create a fixture
Util.spawn({
command:'appdev',
options:['fixture', 'testApplication', 'TestModel', 'model_field:string', 'model_field2:string', 'model_field3:integer'],
shouldEcho:false
})
.then(function(data) {
done();
})
.fail(function(err){
done(err);
});
});
//After the tests are run, delete our fixture directories
after(function(done){
// return to our top level directory
process.chdir(path.join(__dirname, '..'));
// remove /api & /assets directories
var apiGone = Util.removeDir(path.join(__dirname, 'scratchArea', 'api'));
var assetsGone = Util.removeDir(path.join(__dirname, 'scratchArea', 'assets'));
$.when(apiGone, assetsGone).then(function() {
// all good, continue
done();
})
.fail(function(err){
// dang!
done(err);
});
});
// fixtures reuse the appdev resource command to produce the base files
// we won't re-test the basic functionality of appdev resource
// the additional steps for fixtures is to make the controller have
// default data being returned for the basic RESTful routes.
describe('check the TestModelController.js file has the proper data ', function(){
var controllerPath = path.join(__dirname,'scratchArea', 'api', 'controllers', 'TestModelController.js');
var controllerFile = '';
before(function(){
controllerFile = fs.readFileSync(controllerPath, 'utf8');
});
it(' -> the controller exists ',function(){
var found = fs.existsSync(controllerPath);
assert.isTrue(found,' => yup, our controller exists.');
});
it(' -> the controller has method find ',function(){
assert.isTrue((controllerFile.indexOf('find:function') != -1),' => find() method defined');
});
it(' -> the controller has method create ',function(){
assert.isTrue((controllerFile.indexOf('create:function') != -1),' => create() method defined');
});
it(' -> the controller has method update ',function(){
assert.isTrue((controllerFile.indexOf('update:function') != -1),' => update() method defined');
});
it(' -> the controller has method destroy ',function(){
assert.isTrue((controllerFile.indexOf('destroy:function') != -1),' => destroy() method defined');
});
});
});