From 1d1e214a9d5a8953a05a8b3f4b2c5b16c55aa666 Mon Sep 17 00:00:00 2001 From: Tom Howard Date: Thu, 14 Jan 2021 10:48:10 +1100 Subject: [PATCH] test(hal): additional tests for templated HAL links --- README.md | 2 +- src/test/hal.feature | 74 +++++++++++++++++++++++++++++++++++++- src/test/resource.steps.js | 15 ++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca97dd42..9cc32601 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ const json = await apiResource.body() - [x] add support for simple self `_links` - [x] add methods for getting consumed body - [x] add support for more general `_links` - - [ ] add support for templated `_links` + - [x] add support for templated `_links` - [ ] add support for `rels` with an array of links - [ ] add support for curies and curied `_links` - [ ] add support for `_links` in `_embedded` resources diff --git a/src/test/hal.feature b/src/test/hal.feature index b973f675..82e9ca5b 100644 --- a/src/test/hal.feature +++ b/src/test/hal.feature @@ -41,7 +41,6 @@ Feature: Invoke HAL Operation And invokes each of the "next" operations in turn 3 times Then the last resource returned will be the last item in the list - @wip Scenario Outline: Invoke operation - parameterised Given a HAL resource with a "https://waychaser.io/rel/pong" operation that returns the provided "ping" "" parameter When waychaser successfully loads that resource @@ -53,3 +52,76 @@ Feature: Invoke HAL Operation | TYPE | | query | | path | + + Scenario Outline: Invoke operation - parameterised with extra params + Given a HAL resource with a "https://waychaser.io/rel/pong" operation that returns the provided "ping" "" parameter + When waychaser successfully loads that resource + And we invoke the "https://waychaser.io/rel/pong" operation with the input + | ping | pong | + | other | notUsed | + Then resource returned will contain only + | ping | pong | + + Examples: + | TYPE | + | query | + | path | + + Scenario Outline: Invoke operation - multiple parameters of same type + Given a HAL resource with a "https://waychaser.io/rel/pong" operation with the "GET" method that returns the following provided parameters + | NAME | TYPE | + | alpha | | + | bravo | | + | charlie | | + When waychaser successfully loads that resource + And we invoke the "https://waychaser.io/rel/pong" operation with the input + | alpha | one | + | bravo | two | + | charlie | three | + Then resource returned will contain those values + + Examples: + | TYPE | + | query | + | path | + + Scenario Outline: Invoke operation - multiple parameters of same type with extra params + Given a HAL resource with a "https://waychaser.io/rel/pong" operation with the "GET" method that returns the following provided parameters + | NAME | TYPE | + | alpha | | + | bravo | | + | charlie | | + When waychaser successfully loads that resource + And we invoke the "https://waychaser.io/rel/pong" operation with the input + | bravo | two | + | other | notUsed | + | charlie | three | + | alpha | one | + Then resource returned will contain only + | alpha | one | + | bravo | two | + | charlie | three | + + Examples: + | TYPE | + | query | + | path | + + @wip + Scenario Outline: Invoke operation - multiple parameters of different type + Given a HAL resource with a "https://waychaser.io/rel/pong" operation with the "GET" method that returns the following provided parameters + | NAME | TYPE | + | alpha | | + | bravo | | + | charlie | | + When waychaser successfully loads that resource + And we invoke the "https://waychaser.io/rel/pong" operation with the input + | alpha | one | + | bravo | two | + | charlie | three | + Then resource returned will contain those values + + Examples: + | TYPE1 | TYPE2 | + | query | path | + | path | query | diff --git a/src/test/resource.steps.js b/src/test/resource.steps.js index 6b791b69..ea5e8fc0 100644 --- a/src/test/resource.steps.js +++ b/src/test/resource.steps.js @@ -438,6 +438,21 @@ Given( } ) +Given( + 'a HAL resource with a {string} operation with the {string} method that returns the following provided parameters', + async function (relationship, method, dataTable) { + this.currentResourceRoute = await createRandomDynamicResourceRoute.bind( + this + )( + relationship, + method, + dataTable.hashes(), + undefined, + 'application/hal+json' + ) + } +) + Given( 'a resource with a {string} operation with the {string} method that returns the following {string} provided parameters and the content type', async function (relationship, method, contentType, dataTable) {