velocious 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.27",
6
+ "version": "1.0.29",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
@@ -8,6 +8,8 @@ routes.draw((route) => {
8
8
  route.resources("tasks", (route) => {
9
9
  route.get("users")
10
10
  })
11
+
12
+ route.get("ping")
11
13
  })
12
14
 
13
15
  export default {routes}
@@ -0,0 +1,11 @@
1
+ import Controller from "../../../../../src/controller.js"
2
+
3
+ export default class RootController extends Controller {
4
+ ping() {
5
+ this.render({
6
+ json: {
7
+ message: "Pong"
8
+ }
9
+ })
10
+ }
11
+ }
@@ -2,7 +2,6 @@ import {digg} from "diggerize"
2
2
 
3
3
  import Controller from "../../../../../src/controller.js"
4
4
  import Project from "../../models/project.js"
5
- import Task from "../../models/task.js"
6
5
 
7
6
  export default class ProjectsController extends Controller {
8
7
  index() {
@@ -0,0 +1,26 @@
1
+ import fetch from "node-fetch"
2
+ import Dummy from "../dummy/index.js"
3
+
4
+ describe("HttpServer", () => {
5
+ it("handles root get requests", async () => {
6
+ await Dummy.run(async () => {
7
+ const response = await fetch("http://localhost:3006/ping")
8
+ const text = await response.text()
9
+
10
+ expect(response.status).toEqual(200)
11
+ expect(response.statusText).toEqual("OK")
12
+ expect(text).toEqual("{\"message\":\"Pong\"}")
13
+ })
14
+ })
15
+
16
+ it("returns a 404 error when a root get isn't found", async () => {
17
+ await Dummy.run(async () => {
18
+ const response = await fetch("http://localhost:3006/doesnt-exist")
19
+ const text = await response.text()
20
+
21
+ expect(response.status).toEqual(404)
22
+ expect(response.statusText).toEqual("Not Found")
23
+ expect(text).toEqual("Not found!\n")
24
+ })
25
+ })
26
+ })
@@ -213,7 +213,7 @@ export default class VelociousDatabaseQuery {
213
213
  const sql = this.toSql()
214
214
  const results = await this.driver.query(sql)
215
215
 
216
- this.logger.debug(`SQL: sql`)
216
+ this.logger.debug("SQL: ", sql)
217
217
 
218
218
  return results
219
219
  }
@@ -10,10 +10,14 @@ export default class VelociousRouteGetRoute extends BaseRoute {
10
10
  this.regExp = new RegExp(`^(${escapeStringRegexp(name)})(.*)$`)
11
11
  }
12
12
 
13
- matchWithPath({path}) {
14
- if (path.match(this.regExp)) {
13
+ matchWithPath({params, path}) {
14
+ const match = path.match(this.regExp)
15
+
16
+ if (match) {
15
17
  const [_beginnigSlash, _matchedName, restPath] = match
16
18
 
19
+ params.action = this.name
20
+
17
21
  return {restPath}
18
22
  }
19
23
  }
@@ -33,7 +33,9 @@ export default class VelociousRoutesResolver {
33
33
  controllerPath = "./built-in/errors/controller.js"
34
34
  action = "notFound"
35
35
  viewPath = await fs.realpath(`${__dirname}/built-in/errors`) // eslint-disable-line no-undef
36
- } else if (action && controller) {
36
+ } else if (action) {
37
+ if (!controller) controller = "_root"
38
+
37
39
  controllerPath = `${this.configuration.getDirectory()}/src/routes/${controller}/controller.js`
38
40
  viewPath = `${this.configuration.getDirectory()}/src/routes/${controller}`
39
41
  } else {
@@ -34,7 +34,7 @@ class ExpectToChange {
34
34
  const difference = this.newCount - this.oldCount
35
35
 
36
36
  if (difference != this.count) {
37
- throw new Error(`Expected to change by ${count} but changed by ${difference}`)
37
+ throw new Error(`Expected to change by ${this.count} but changed by ${difference}`)
38
38
  }
39
39
  }
40
40
  }
@@ -68,7 +68,7 @@ class Expect {
68
68
  await expectation.runBefore()
69
69
  }
70
70
 
71
- await this._object()
71
+ const result = await this._object()
72
72
 
73
73
  for (const expectation of this.expectations) {
74
74
  await expectation.runAfter()
@@ -77,6 +77,8 @@ class Expect {
77
77
  for (const expectation of this.expectations) {
78
78
  await expectation.execute()
79
79
  }
80
+
81
+ return result
80
82
  }
81
83
 
82
84
  toHaveAttributes(result) {