Skip to content

Commit 878aeb0

Browse files
authored
Refactor tests
Remove mocked API calls from tests
2 parents e7962ce + 745695e commit 878aeb0

File tree

9 files changed

+197
-444
lines changed

9 files changed

+197
-444
lines changed

.github/workflows/authsignal.png

321 KB
Loading

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jobs:
1515
matrix:
1616
ruby:
1717
- 3.0.3
18-
18+
env:
19+
AUTHSIGNAL_API_URL: ${{ secrets.AUTHSIGNAL_API_URL }}
20+
AUTHSIGNAL_API_SECRET_KEY: ${{ secrets.AUTHSIGNAL_API_SECRET_KEY }}
1921
steps:
2022
- uses: actions/checkout@v2
2123
- name: Set up Ruby

.github/workflows/release-package.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
if: contains(github.ref, 'refs/tags/')
1717
uses: cadwallion/publish-rubygems-action@master
1818
env:
19+
AUTHSIGNAL_API_URL: ${{ secrets.AUTHSIGNAL_API_URL }}
20+
AUTHSIGNAL_API_SECRET_KEY: ${{ secrets.AUTHSIGNAL_API_SECRET_KEY }}
1921
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2022
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
2123
RELEASE_COMMAND: bundle exec rake -f RakefileRelease

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
# rspec failure tracking
1212
.rspec_status
13+
14+
.env

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ source "https://rubygems.org"
44

55
# Specify your gem's dependencies in authsignal-ruby.gemspec
66
gemspec
7+
8+
group :test do
9+
gem 'dotenv'
10+
end

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ GEM
1515
bigdecimal
1616
rexml
1717
diff-lcs (1.5.1)
18+
dotenv (3.1.7)
1819
faraday (2.12.0)
1920
faraday-net_http (>= 2.0, < 3.4)
2021
json
@@ -56,6 +57,7 @@ PLATFORMS
5657

5758
DEPENDENCIES
5859
authsignal-ruby!
60+
dotenv
5961
rake (~> 13.0)
6062
rspec (~> 3.2)
6163
webmock (~> 3.14)

README.md

Lines changed: 28 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Authsignal Server Ruby SDK
1+
<img width="1070" alt="Authsignal" src="https://raw.githubusercontent.com/authsignal/authsignal-node/main/.github/images/authsignal.png">
22

3-
Check out our [official Ruby SDK documentation](https://docs.authsignal.com/sdks/server/ruby), and [Ruby on Rails Quickstart Guide](https://docs.authsignal.com/quickstarts/ruby-on-rails).
3+
# Authsignal Ruby SDK
4+
5+
The Authsignal Ruby library for server-side applications.
46

57
## Installation
68

@@ -10,72 +12,11 @@ Add this line to your application's Gemfile:
1012
gem "authsignal-ruby"
1113
```
1214

13-
And then execute:
14-
15-
$ bundle install
16-
17-
Or install it yourself as:
18-
19-
$ gem install authsignal-ruby
20-
21-
## Initialization
22-
23-
Initialize the Authsignal Ruby SDK, ensuring you do not hard code the Authsignal Secret Key, always keep this safe.
24-
25-
In Ruby on Rails, you would typically place this code block in a file like `config/initializers/authsignal.rb`
26-
27-
```ruby
28-
Authsignal.setup do |config|
29-
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
30-
end
31-
```
32-
33-
You can find your `api_secret_key` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).
34-
35-
You must specify the correct `api_url` for your tenant's region.
15+
## Documentation
3616

37-
| Region | API URL |
38-
| ----------- | ----------------------------------- |
39-
| US (Oregon) | https://signal.authsignal.com/v1 |
40-
| AU (Sydney) | https://au.signal.authsignal.com/v1 |
41-
| EU (Dublin) | https://eu.signal.authsignal.com/v1 |
17+
Refer to our [SDK documentation](https://docs.authsignal.com/sdks/server/overview) for information on how to use this SDK.
4218

43-
For example, to set the API URL to use our AU region:
44-
45-
```
46-
require 'authsignal'
47-
48-
Authsignal.setup do |config|
49-
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
50-
config.api_url = "https://au.signal.authsignal.com/v1"
51-
52-
# If you would like the Authsignal client to retry requests due to network issues
53-
config.retry = true # default value: false
54-
55-
# If you would like to inspect raw request/response in development
56-
config.debug = true # default value: false
57-
end
58-
```
59-
60-
## Usage
61-
62-
Authsignal's server side signal API has four main api calls `track`, `get_action`, `get_user`, `enroll_verified_authenticator`.
63-
64-
For more details on these api calls, refer to our [official Ruby SDK docs](https://docs.authsignal.com/sdks/server/ruby#track).
65-
66-
Example:
67-
68-
```ruby
69-
Authsignal.track user_id: 'AS_001', action: 'withdraw', idempotency_key: 'a_random_hash'
70-
71-
# returns:
72-
# {
73-
# success?: true,
74-
# state: 'ALLOW',
75-
# idempotency_key: 'a_random_hash',
76-
# ... rest of payload ...
77-
# }
78-
```
19+
Or check out our [Ruby on Rails Quickstart Guide](https://docs.authsignal.com/quickstarts/ruby-on-rails).
7920

8021
### Response & Error handling
8122

@@ -84,42 +25,35 @@ The Authsignal SDK offers two response formats. By default, its methods return t
8425
Example:
8526

8627
```ruby
87-
Authsignal.enroll_verified_authenticator user_id: 'AS_001',
88-
authenticator: {
89-
oob_channel: 'INVALID', email: 'joebloke@authsignal.com'
90-
}
28+
Authsignal.enroll_verified_authenticator(
29+
user_id: 'AS_001',
30+
attributes: {
31+
verification_method: 'INVALID',
32+
email: 'hamish@authsignal.com'
33+
}
34+
)
9135

9236
# returns:
93-
# {
94-
# success?: false,
95-
# status_code: 400,
96-
# error_code: 'invalid_request',
97-
# error_description: '/body/oobChannel must be equal to one of the allowed values'
98-
# }
37+
{
38+
"error": "invalid_request",
39+
"errorCode": "invalid_request",
40+
"errorDescription": "body.verificationMethod must be equal to one of the allowed values - allowedValues: AUTHENTICATOR_APP,EMAIL_MAGIC_LINK,EMAIL_OTP,SMS"
41+
}
9942
```
10043

10144
All methods have a bang (!) counterpart that raises an Authsignal::ApiError if the request fails.
10245

10346
Example:
10447

10548
```ruby
106-
Authsignal.enroll_verified_authenticator! user_id: 'AS_001',
107-
authenticator: {
108-
oob_channel: 'INVALID', email: 'joebloke@authsignal.com'
109-
}
49+
Authsignal.enroll_verified_authenticator!(
50+
user_id: 'AS_001',
51+
attributes: {
52+
verification_method: 'INVALID',
53+
email: 'hamish@authsignal.com'
54+
}
55+
)
11056

11157
# raise:
112-
# <Authsignal::ApiError: AuthsignalError: 400 - /body/oobChannel must be equal to one of the allowed values. status_code: 401, error_code: invalid_request, error_description: /body/oobChannel must be equal to one of the allowed values.
113-
```
114-
115-
## Development
116-
117-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` or `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
118-
119-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
120-
121-
Log request/response against test server: `Authsignal.configuration.debug = true`
122-
123-
## License
124-
125-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58+
<Authsignal::ApiError: AuthsignalError: 400 - body.verificationMethod must be equal to one of the allowed values - allowedValues: AUTHENTICATOR_APP,EMAIL_MAGIC_LINK,EMAIL_OTP,SMS.
59+
```

0 commit comments

Comments
 (0)