Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Created equivalents AST-based tests, which are blueprint-based.
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Mar 16, 2016
1 parent 45a592c commit 4cc180f
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 38 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -24,10 +24,10 @@
"coffee-script": "^1.10.0",
"coffeelint": "^1.14.2",
"coveralls": "^2.11.6",
"drafter": "^0.2.8",
"jscoverage": "^0.6.0",
"mocha": "^2.3.4",
"mocha-lcov-reporter": "^1.0.0"
"mocha-lcov-reporter": "^1.0.0",
"protagonist": "^1.3.0-pre.0"
},
"keywords": [
"api",
Expand Down
File renamed without changes.
69 changes: 69 additions & 0 deletions test/fixtures/blueprint.apib
@@ -0,0 +1,69 @@
FORMAT: X-1A

# Machines API

# Group Machines

# Machines collection [/machines]

## Create a Machine [POST]
+ Request (application/json)

{
"type": "bulldozer",
"name": "willy"
}

+ Response 202 (application/json)

{
"mesage": "Accepted"
}


## Retreive all Machines [GET]

+ Response 200 (application/json)

[{
"_id": "52341870ed55224b15ff07ef",
"type": "bulldozer",
"name": "willy"
}]

# Machine [/machines/{name}]
+ Parameters
+ name (required,`willy`)

## Update a Machine [PUT]

+ Request (application/json)

{
"name": "waldo"
}

+ Response 200 (application/json)

{
"type": "bulldozer",
"name": "waldo",
"_id": "5229c6e8e4b0bd7dbb07e29c"
}

## Retrieve a Machine [GET]
+ Parameters
+ name (required,`waldo`)

+ Response 200 (text/plain)

{
"type": "bulldozer",
"name": "waldo",
"_id": "5229c6e8e4b0bd7dbb07e29c"
}

## Delete Message [DELETE]
+ Parameters
+ name (required,`waldo`)
+ Response 204
37 changes: 37 additions & 0 deletions test/fixtures/multiple-examples.apib
@@ -0,0 +1,37 @@
FORMAT: 1A

# Machines API

# Group Machines

# Machines collection [/machines/{id}]
+ Parameters
- id (number, `1`)

## Get Machines [GET]

- Request (application/json)
+ Parameters
- id (number, `2`)

- Response 200 (application/json; charset=utf-8)

[
{
"type": "bulldozer",
"name": "willy"
}
]

- Request (application/json)
+ Parameters
- id (number, `3`)

- Response 200 (application/json; charset=utf-8)

[
{
"type": "bulldozer",
"name": "willy"
}
]
4 changes: 4 additions & 0 deletions test/fixtures/simple-unnamed.apib
@@ -0,0 +1,4 @@
# GET /message
+ Response 200 (text/plain)

Hello World!
18 changes: 18 additions & 0 deletions test/fixtures/single-get.apib
@@ -0,0 +1,18 @@
FORMAT: 1A

# Machines API

# Group Machines

# Machines collection [/machines]

## Get Machines [GET]

- Response 200 (application/json; charset=utf-8)

[
{
"type": "bulldozer",
"name": "willy"
}
]
27 changes: 11 additions & 16 deletions test/integration/blueprint-transactions-test.coffee
@@ -1,14 +1,9 @@
Drafter = require 'drafter'
protagonist = require 'protagonist'
{assert} = require 'chai'

blueprintTransactions = require '../../src/blueprint-transactions'

describe "compiled transaction paths", () ->
drafter = null

beforeEach () ->
drafter = new Drafter

describe "Full notation with multiple request-response pairs", () ->

it 'should have expected path', (done) ->
Expand All @@ -30,8 +25,8 @@ describe "compiled transaction paths", () ->

expected = "Some API Name:Some Group Name:Some Resource Name:Some Action Name:Example 2"

drafter.make code, (drafterError, result) ->
return done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
paths = []
transactions = blueprintTransactions.compile(result.ast).transactions
console.log JSON.stringify transactions, null, 2
Expand All @@ -57,8 +52,8 @@ describe "compiled transaction paths", () ->

expected = "Some API Name::Some Resource Name:Some Action Name:Example 1"

drafter.make code, (drafterError, result) ->
return done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
paths = []
transactions = blueprintTransactions.compile(result.ast).transactions
for transaction in transactions
Expand All @@ -79,8 +74,8 @@ describe "compiled transaction paths", () ->

expected = "::Some Resource Name:Some Action Name:Example 1"

drafter.make code, (drafterError, result) ->
return done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
paths = []
transactions = blueprintTransactions.compile(result.ast).transactions
for transaction in transactions
Expand All @@ -103,8 +98,8 @@ describe "compiled transaction paths", () ->

expected = "My API\\: Revamp::Some Resource Name:Some Action Name:Example 1"

drafter.make code, (drafterError, result) ->
return done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
paths = []
transactions = blueprintTransactions.compile(result.ast).transactions
for transaction in transactions
Expand All @@ -124,8 +119,8 @@ describe "compiled transaction paths", () ->

expected = "::/message:GET:Example 1"

drafter.make code, (drafterError, result) ->
return done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
paths = []
transactions = blueprintTransactions.compile(result.ast).transactions
for transaction in transactions
Expand Down
@@ -1,12 +1,12 @@
{assert} = require 'chai'
Drafter = require 'drafter'
protagonist = require 'protagonist'
fs = require 'fs'

blueprintAstToRuntime = require '../../src/blueprint-ast-to-runtime'
blueprintAstToRuntime = require '../../../src/blueprint-ast-to-runtime'


describe "blueprintAstToRuntime()", () ->
blueprintAst = require '../fixtures/blueprint-ast'
describe "blueprintAstToRuntime() [AST]", () ->
blueprintAst = require '../../fixtures/blueprint-ast'
data = {}
filename = './path/to/blueprint.apib'
before () ->
Expand Down Expand Up @@ -93,7 +93,7 @@ describe "blueprintAstToRuntime()", () ->

describe 'when some warning in URI expanding appear', () ->
it 'should have piped all warnings from expandUriTemplate', () ->
blueprintAst = require '../fixtures/blueprint-ast'
blueprintAst = require '../../fixtures/blueprint-ast'
blueprintAst['resourceGroups'][0]['resources'][1]['parameters'] = {}
blueprintAst['resourceGroups'][0]['resources'][1]['actions'][0]['parameters'] = {}

Expand All @@ -102,7 +102,7 @@ describe "blueprintAstToRuntime()", () ->

describe 'when some error in URI parameters validation appear', () ->
it 'should have piped all errors from validateParameters', () ->
blueprintAst = require '../fixtures/blueprint-ast'
blueprintAst = require '../../fixtures/blueprint-ast'
params = [
{
name: 'name'
Expand All @@ -121,7 +121,7 @@ describe "blueprintAstToRuntime()", () ->

describe 'when some error in URI expanding appear', () ->
it 'should have piped all errors from expandUriTemplate', () ->
blueprintAst = require '../fixtures/blueprint-ast'
blueprintAst = require '../../fixtures/blueprint-ast'
blueprintAst['resourceGroups'][0]['resources'][1]['uriTemplate'] = '/machines{{/name}'
data = blueprintAstToRuntime blueprintAst
assert.notEqual data['errors'].length, 0
Expand All @@ -143,7 +143,7 @@ describe "blueprintAstToRuntime()", () ->
transaction = null
filename = './path/to/blueprint.apib'
before () ->
simpleUnnamedAst = require '../fixtures/simple-unnamed-ast'
simpleUnnamedAst = require '../../fixtures/simple-unnamed-ast'
data = blueprintAstToRuntime simpleUnnamedAst, filename
transaction = data['transactions'][0]

Expand All @@ -166,7 +166,7 @@ describe "blueprintAstToRuntime()", () ->
transactions = null

before () ->
simpleUnnamedAst = require '../fixtures/multiple-examples'
simpleUnnamedAst = require '../../fixtures/multiple-examples'
transactions = blueprintAstToRuntime(simpleUnnamedAst, filename)['transactions']

it 'should set exampleName for first transaction to "Example 1"', () ->
Expand All @@ -181,7 +181,7 @@ describe "blueprintAstToRuntime()", () ->
transactions = null

before () ->
simpleUnnamedAst = require '../fixtures/single-get'
simpleUnnamedAst = require '../../fixtures/single-get'
transactions = blueprintAstToRuntime(simpleUnnamedAst, filename)['transactions']

it 'should let example name intact', () ->
Expand All @@ -191,11 +191,10 @@ describe "blueprintAstToRuntime()", () ->
transactions = null

before (done) ->
filename = './test/fixtures/arbitrary-action.md'
filename = './test/fixtures/arbitrary-action.apib'
code = fs.readFileSync(filename).toString()
drafter = new Drafter
drafter.make code, (drafterError, result) ->
done(drafterError) if drafterError
protagonist.parse code, {type: 'ast'}, (err, result) ->
return done(err) if err
transactions = blueprintAstToRuntime(result['ast'], filename)['transactions']
done()

Expand All @@ -211,5 +210,3 @@ describe "blueprintAstToRuntime()", () ->

it 'second (arbitrary) action should have its method', ->
assert.equal transactions[1].request.method, 'GET'


@@ -1,8 +1,8 @@
{assert} = require 'chai'
blueprintTransactions = require '../../src/blueprint-transactions'
ast = require '../fixtures/blueprint-ast'
blueprintTransactions = require '../../../src/blueprint-transactions'
ast = require '../../fixtures/blueprint-ast'

describe 'blueprintTransactions', () ->
describe 'blueprintTransactions [AST]', () ->

it 'exports an object', () ->
assert.isObject blueprintTransactions
Expand Down Expand Up @@ -38,4 +38,3 @@ describe 'blueprintTransactions', () ->
for transaction, index in returnedObject.transactions
console.log transaction.path
assert.property transaction, 'path', "Missing 'path' property on transaction #{index}"

0 comments on commit 4cc180f

Please sign in to comment.