-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
e2e_test.sh
executable file
Β·172 lines (138 loc) Β· 4.47 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
#!/usr/bin/env bash
set -e
rm -rf ./node_modules
npm install -g @foal/cli
rm -rf e2e-test-temp
mkdir e2e-test-temp
cd e2e-test-temp
# Test app creation
npx --yes @foal/cli createapp my-app
cd my-app
# Check some compilation errors
if grep -Rl "../../Users/loicp" .; then
echo "Compilation error: \"../../Users/loicp\" has been found in one of the builds."
exit 1
fi
# Test the generators
npx foal g entity flight
npx foal g hook foo-bar
npx foal g service foo
npx foal g controller bar --register
npx foal g rest-api product --register
npx foal g script bar-script
# Test linting
npm run lint
# Build and run the unit tests
npm run build:test
npm run start:test
# Make and run the migrations
npm run makemigrations
npm run migrations
# Build and run the e2e tests
npm run build:e2e
npm run start:e2e
# Build the app
npm run build
# Test the application when it is started
node 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 as expected."
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
kill -9 $(ps aux | grep '\snode\s')
# Test the default shell scripts to create users.
npx foal run create-user
#################################################################
# Repeat (almost) the same tests with a MongoDB and YAML project
#################################################################
cd ..
# Test app creation
npx @foal/cli 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 linting
npm run lint
# Build and run the unit tests
npm run build:test
npm run start:test
# Build and run the e2e tests
npm run build:e2e
npm run start:e2e
# Build the app
npm run build
# Test the application when it is started
node 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
kill -9 $(ps aux | grep '\snode\s')
# Test the default shell scripts to create users.
npx foal run create-user