Skip to content

Commit 005edfd

Browse files
committed
Make a basic GET request with Hyper!
1 parent de0c27d commit 005edfd

File tree

8 files changed

+121
-15
lines changed

8 files changed

+121
-15
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
- ENGINE=lucee@5
1212
- ENGINE=adobe@2016
1313
- ENGINE=adobe@11
14-
- ENGINE=adobe@10
1514
before_install:
1615
- sudo apt-key adv --keyserver keys.gnupg.net --recv 6DA70622
1716
- sudo echo "deb http://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list

models/Builder.cfc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
component {
2+
3+
function get( url ) {
4+
var req = new Hyper.models.HyperRequest();
5+
req.setUrl( arguments.url );
6+
return req.get();
7+
}
8+
9+
}

models/HyperRequest.cfc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
component accessors="true" {
2+
3+
property name="url";
4+
property name="method";
5+
6+
function get() {
7+
setMethod( "GET" );
8+
return makeRequest();
9+
}
10+
11+
function makeRequest() {
12+
var res = new Hyper.models.HyperResponse();
13+
return res.populateFromCFHTTP(
14+
makeCFHTTPRequest()
15+
);
16+
}
17+
18+
private function makeCFHTTPRequest() {
19+
local.res = "";
20+
cfhttp(
21+
result = "local.res"
22+
url = getUrl(),
23+
method = getMethod()
24+
) {
25+
26+
}
27+
return local.res;
28+
}
29+
30+
}

models/HyperResponse.cfc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
component accessors="true" {
2+
3+
property name="statusCode";
4+
property name="data";
5+
6+
function json() {
7+
return deserializeJSON( getData() );
8+
}
9+
10+
function populateFromCFHTTP( res ) {
11+
setStatusCode( res.responseheader.status_code );
12+
setData( res.filecontent );
13+
14+
return this;
15+
}
16+
17+
}

tests/Application.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ component {
1010
this.mappings[ "/tests" ] = testsPath;
1111
rootPath = REReplaceNoCase( this.mappings[ "/tests" ], "tests(\\|/)", "" );
1212
this.mappings[ "/root" ] = rootPath;
13+
this.mappings[ "/hyper" ] = rootPath;
1314
this.mappings[ "/testingModuleRoot" ] = listDeleteAt( rootPath, listLen( rootPath, '\/' ), "\/" );
1415
this.mappings[ "/app" ] = testsPath & "resources/app";
1516
this.mappings[ "/coldbox" ] = testsPath & "resources/app/coldbox";
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
2+
3+
function run() {
4+
describe( "GET requests", function() {
5+
beforeEach( function() {
6+
variables.hyper = getInstance( "Builder@Hyper" );
7+
} );
8+
9+
afterEach( function() {
10+
if ( variables.keyExists( "hyper" ) ) {
11+
variables.delete( "hyper" );
12+
}
13+
} );
14+
15+
it( "can make a GET request", function() {
16+
var res = hyper.get( "https://swapi.co/api/people/1" );
17+
expect( res ).toBeInstanceOf(
18+
"HyperResponse",
19+
"A HyperResponse object should have been returned."
20+
);
21+
var data = res.json();
22+
expect( data ).toBeStruct(
23+
"Expected to deserialize JSON data from the response."
24+
);
25+
expect( data ).toBe( {
26+
"name": "Luke Skywalker",
27+
"height": "172",
28+
"mass": "77",
29+
"hair_color": "blond",
30+
"skin_color": "fair",
31+
"eye_color": "blue",
32+
"birth_year": "19BBY",
33+
"gender": "male",
34+
"homeworld": "https://swapi.co/api/planets/1/",
35+
"films": [
36+
"https://swapi.co/api/films/2/",
37+
"https://swapi.co/api/films/6/",
38+
"https://swapi.co/api/films/3/",
39+
"https://swapi.co/api/films/1/",
40+
"https://swapi.co/api/films/7/"
41+
],
42+
"species": [
43+
"https://swapi.co/api/species/1/"
44+
],
45+
"vehicles": [
46+
"https://swapi.co/api/vehicles/14/",
47+
"https://swapi.co/api/vehicles/30/"
48+
],
49+
"starships": [
50+
"https://swapi.co/api/starships/12/",
51+
"https://swapi.co/api/starships/22/"
52+
],
53+
"created": "2014-12-09T13:50:51.644000Z",
54+
"edited": "2014-12-20T21:17:56.891000Z",
55+
"url": "https://swapi.co/api/people/1/"
56+
} );
57+
} );
58+
} );
59+
}
60+
61+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
2+
23
function run() {
34
describe( "Sample Integration Specs", function() {
45
it( "can run integration specs with the module activated", function() {
56
expect( getController().getModuleService().isModuleRegistered( "hyper" ) ).toBeTrue();
6-
var event = execute( event = "Main.index", renderResults = true );
7-
expect( event.getPrivateCollection().welcomeMessage )
8-
.toBe( "Welcome to ColdBox!" );
97
} );
108
} );
119
}
12-
}
10+
11+
}

tests/specs/unit/SampleUnitSpec.cfc

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)