Skip to content

Commit

Permalink
Refactor app for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
pfreitag committed May 6, 2020
1 parent 9772d61 commit 2c30e21
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/testbox
File renamed without changes.
4 changes: 3 additions & 1 deletion app/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM foundeo/minibox:latest

COPY ./ /app/

COPY ../tests/ /app/tests/
RUN cd /app/

RUN box install

EXPOSE 8855

Expand Down
8 changes: 8 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"devDependencies":{
"testbox":"^4.0.0"
},
"installPaths":{
"testbox":"tests/testbox/"
}
}
17 changes: 0 additions & 17 deletions db/news.sql

This file was deleted.

4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ version: "3"

services:
calc_app:
build: app/
#image: foundeo/minibox:latest
#command: ["box", "server", "start", "port=8847", "[email protected]", "--console"]
build: ./
ports:
- "8855:8855"

File renamed without changes.
8 changes: 8 additions & 0 deletions server-calc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name":"calc",
"web":{
"http":{
"port":"8855"
}
}
}
2 changes: 1 addition & 1 deletion app/services/calc.cfc → services/calc.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ component {

remote function add(x, y) {
return x+y;

}

}
8 changes: 8 additions & 0 deletions tests/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
component {
this.name = "calcTests";

this.mappings = {
"/testbox" = getDirectoryFromPath(getCurrentTemplatePath()) & "testbox",
"/specs" = getDirectoryFromPath(getCurrentTemplatePath()) & "specs"
};
}
12 changes: 12 additions & 0 deletions tests/cfm/test.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<cfset calc = new services.calc()>

<cfset result = calc.add(5,3)>

<cfif result EQ 8>
PASS: Result was 8
<cfelse>
Fail: Result was: <cfoutput>#encodeForHTML(result)#</cfoutput>
<cfheader statuscode="500" statustext="Fail">
</cfif>

<!--- this works but there are better ways to write tests --->
15 changes: 15 additions & 0 deletions tests/curl/cfm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

#run a simple curl test of our API
echo "\nRUNNING SIMPLE CFML TEST SUITE:\n"

http_code=$(curl --verbose -s -o /tmp/cfm-result.txt -w '%{http_code}' "http://127.0.0.1:8855/tests/cfm/test.cfm";)

cat /tmp/cfm-result.txt

if [ "$http_code" -eq "200" ]; then
echo "\nPASS: HTTP Status Code was 200"
else
echo "\nFAIL: Status Code: $http_code"
exit 1
fi
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/runner.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<cfparam name="reporter" default="html">
<cfset r = new testbox.system.TestBox( directory="specs", reporter=reporter, verbose=true) >
<cfoutput>#r.run()#</cfoutput>
18 changes: 18 additions & 0 deletions tests/specs/CalcTest.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
component extends="testbox.system.BaseSpec" {

function run(testResults, testBox) {

describe("Test Addition", function() {
it("Should be able to add two positive integers", function() {
var calc = new services.calc();
expect(calc.add(5,3)).toBe(8);
});

it("Should be able to add negative integers", function() {
var calc = new services.calc();
expect(calc.add(-6,3)).toBe(-3);
});
});
}

}
File renamed without changes.

0 comments on commit 2c30e21

Please sign in to comment.