forked from FoalTS/foal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_test.sh
executable file
·175 lines (141 loc) · 4.52 KB
/
e2e_test.sh
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
#!/usr/bin/env bash
set -e
mkdir e2e-test-temp
cd e2e-test-temp
# Test app creation
foal createapp my-app
cd my-app
# Check some compilation errors
if grep -Ril "../../Users/loicp" .; then
echo "Compilation error: \"../../Users/loicp\" has been found in one of the builds."
exit 1
fi
# Test the generators
foal g entity flight
foal g hook foo-bar
foal g service foo
foal g controller bar --register
foal g rest-api product --register
foal g sub-app bar-foo
foal g script bar-script
# Test linting
npm run lint
# Build and run the unit tests
npm run build:test
npm run start:test
# Build the app
npm run build:app
# Build and run the migrations
npm run migration:generate -- -n my-migration
npm run build:migrations
npm run migration:run
# Build and run the e2e tests
npm run build:e2e
npm run start:e2e
# Test the application when it is started
pm2 start build/index.js
sleep 1
response=$(
curl http://localhost:3001 \
--write-out %{http_code} \
--silent \
--output /dev/null \
)
test "$response" -ge 200 && test "$response" -le 299
# Test the REST API
function test_rest_api () {
echo "Requesting $1 $2"
STATUS=$(
curl "$2" \
-X $1 \
--write-out %{http_code} \
--silent \
--output /dev/null \
)
if [ $STATUS -eq $3 ]; then
echo "SUCCESS: Got $STATUS! Expected $3."
else
echo "ERROR: Got $STATUS. Expected $3..."
exit 1
fi
}
function test_rest_api_with_body () {
echo "Requesting $1 $2"
STATUS=$(
curl "$2" \
-X $1 \
-d "$4" \
-H "Content-Type: application/json" \
--write-out %{http_code} \
--silent \
--output /dev/null \
)
if [ $STATUS -eq $3 ]; then
echo "SUCCESS: Got $STATUS! Expected $3."
else
echo "ERROR: Got $STATUS. Expected $3..."
exit 1
fi
}
test_rest_api GET "http://localhost:3001/products" 200
test_rest_api GET "http://localhost:3001/products/20000" 404
test_rest_api GET "http://localhost:3001/products/ab" 400
test_rest_api_with_body POST "http://localhost:3001/products" 201 '{ "text": "value1" }'
test_rest_api_with_body POST "http://localhost:3001/products" 400 '{}'
test_rest_api_with_body POST "http://localhost:3001/products/1" 404
test_rest_api GET "http://localhost:3001/products/1" 200
test_rest_api_with_body PUT "http://localhost:3001/products" 404
test_rest_api_with_body PUT "http://localhost:3001/products/1" 200 '{ "text": "value2" }'
test_rest_api_with_body PUT "http://localhost:3001/products/1" 400 '{}'
test_rest_api_with_body PUT "http://localhost:3001/products/20000" 404 '{ "text": "value2" }'
test_rest_api_with_body PUT "http://localhost:3001/products/ab" 400 '{ "text": "value2" }'
test_rest_api_with_body PATCH "http://localhost:3001/products" 404
test_rest_api_with_body PATCH "http://localhost:3001/products/1" 200 '{ "text": "value2" }'
test_rest_api_with_body PATCH "http://localhost:3001/products/20000" 404 '{ "text": "value2" }'
test_rest_api_with_body PATCH "http://localhost:3001/products/ab" 400 '{ "text": "value2" }'
test_rest_api DELETE "http://localhost:3001/products" 404
test_rest_api DELETE "http://localhost:3001/products/1" 204
test_rest_api DELETE "http://localhost:3001/products/1" 404
test_rest_api DELETE "http://localhost:3001/products/ab" 400
pm2 delete index
# Test the default shell scripts to create permissions, groups and users.
npm run build:scripts
foal run create-user
#################################################################
# Repeat (almost) the same tests with a Mongoose and YAML project
#################################################################
cd ..
# Test app creation
foal createapp my-mongodb-app --mongodb --yaml
cd my-mongodb-app
# Check some compilation errors
if grep -Ril "../../Users/loicp" .; then
echo "Compilation error: \"../../Users/loicp\" has been found in one of the builds."
exit 1
fi
# Test the generators
foal g model flight
# Test linting
npm run lint
# Build and run the unit tests
npm run build:test
npm run start:test
# Build the app
npm run build:app
# Build and run the e2e tests
npm run build:e2e
npm run start:e2e
# Test the application when it is started
PORT=3001 pm2 start build/index.js
sleep 1
response=$(
curl http://localhost:3001 \
--write-out %{http_code} \
--silent \
--output /dev/null \
)
test "$response" -ge 200 && test "$response" -le 299
pm2 delete index
# Test the default shell scripts to create users.
npm run build:scripts
foal run create-user