Skip to content

Commit

Permalink
Merge pull request #93 from zaikio/support-system-tests
Browse files Browse the repository at this point in the history
Add SystemTestHelper for easier test setup & bump version to v0.12.1
  • Loading branch information
nickcampbell18 authored Apr 23, 2021
2 parents 1b52309 + b7bdf70 commit bf36632
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.12.1 - 2021-04-23

* Add `Zaikio::OAuthClient::SystemTestHelper` for working with system tests
([instructions here](https://github.com/zaikio/zaikio-oauth_client/blob/main/README.md#testing))

## 0.12.0 - 2021-04-23

* **BREAKING CHANGE:** Instead of working `cookies.encrypted` we will switch to `session` because the session cookie will be `httponly` and therefore can prevent XSS attack that set the cookie to another value. See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
zaikio-oauth_client (0.12.0)
zaikio-oauth_client (0.12.1)
actionpack (>= 5.0.0)
activerecord (>= 5.0.0)
activesupport (>= 5.0.0)
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ class MyControllerTest < ActionDispatch::IntegrationTest
end
```

For system tests (e.g. with a separate browser instance), there's a special helper:

```rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include Zaikio::OAuthClient::SystemTestHelper
test "does request" do
person = people(:my_person)
logged_in_as(person)
visit "/"
end
end
```

#### Authenticated requests

Now further requests to the Directory API or to other Zaikio APIs should be made. For this purpose the OAuthClient provides a helper method `with_auth` that automatically fetches an access token from the database, requests a refresh token or creates a new access token via client credentials flow.
Expand Down
18 changes: 18 additions & 0 deletions lib/zaikio/oauth_client/system_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative "./test_helper"

module Zaikio
module OAuthClient
module SystemTestHelper
include ::Zaikio::OAuthClient::TestHelper

def set_session(key, value)
visit "/zaikio/oauth_client/test_helper/session?#{{ key: key, id: value }.to_query}"
end

def get_session(key)
visit "/zaikio/oauth_client/test_helper/get_session?#{{ key: key }.to_query}"
page.text
end
end
end
end
2 changes: 1 addition & 1 deletion lib/zaikio/oauth_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Zaikio
module OAuthClient
VERSION = "0.12.0".freeze
VERSION = "0.12.1".freeze
end
end

0 comments on commit bf36632

Please sign in to comment.