add api:users spec

This commit is contained in:
ZippyDev 2020-07-26 19:04:01 -06:00
parent e2e38dc88d
commit fed9140ce3
10 changed files with 148 additions and 7 deletions

View File

@ -4,9 +4,9 @@ module BtcPay
module Client
module Api
class Base
def initialize(client:, logger:)
def initialize(client:)
@client = client
@logger = logger
@logger = @client.logger
end
protected

View File

@ -19,6 +19,8 @@ module BtcPay
API_PATH = '/api/v1'
DEFAULT_TIMEOUT = 10
attr_reader :logger
# @param config [BtcPay::Client::Config]
# @param logger [Logger]
# @param timeout [Integer] Defaults to DEFAULT_TIMEOUT
@ -51,12 +53,12 @@ module BtcPay
end
def users
@users ||= Api::Users.new(client: self, logger: logger)
@users ||= Api::Users.new(client: self)
end
private
attr_reader :config, :logger
attr_reader :config
# @return [Hash]
def default_headers

View File

@ -0,0 +1,47 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/users/me
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.0
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Mon, 27 Jul 2020 00:04:14 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '128'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"id":"4d164e21-c0a1-44c4-8dc9-3d15be78b174","email":"admin@admin.com","emailConfirmed":false,"requiresEmailConfirmation":false}'
recorded_at: Mon, 27 Jul 2020 00:04:15 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,51 @@
---
http_interactions:
- request:
method: post
uri: http://localhost:49392/api/v1/users
body:
encoding: UTF-8
string: '{"email":"btcpaygem-8540b3f4aec685de9a61486ff24e3455@spec.com","password":"password","isAdministrator":false}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.0
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
Content-Length:
- '109'
Host:
- localhost:49392
response:
status:
code: 201
message: Created
headers:
Date:
- Mon, 27 Jul 2020 01:00:30 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '813'
Location:
- http://localhost:49392/Users
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"notifications":null,"userStores":null,"requiresEmailConfirmation":false,"storedFiles":null,"u2FDevices":null,"apiKeys":null,"id":"7e8ff7f1-df17-4d1a-a84c-4aac98cfd272","userName":"btcpaygem-8540b3f4aec685de9a61486ff24e3455@spec.com","normalizedUserName":"BTCPAYGEM-8540B3F4AEC685DE9A61486FF24E3455@SPEC.COM","email":"btcpaygem-8540b3f4aec685de9a61486ff24e3455@spec.com","normalizedEmail":"BTCPAYGEM-8540B3F4AEC685DE9A61486FF24E3455@SPEC.COM","emailConfirmed":false,"passwordHash":"AQAAAAEAACcQAAAAEEWoj7yJjEJRhSPdy93+LD9aoPYH2FAZKRp+ubsfcBK0MYWAk2SASMWGKTcyhJyJzw==","securityStamp":"AXSOMQHRCK7LW675TNUYOP2NSAVDJ6XX","concurrencyStamp":"dc445406-ea20-417b-abb6-920b6d324846","phoneNumber":null,"phoneNumberConfirmed":false,"twoFactorEnabled":false,"lockoutEnd":null,"lockoutEnabled":true,"accessFailedCount":0}'
recorded_at: Mon, 27 Jul 2020 01:00:30 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::Users, :vcr do
let(:client) { build(:client) }
subject { described_class.new(client: client) }
describe 'GET #me' do
let(:response) { subject.me }
it { expect(response).to be_success }
end
describe 'POST #create' do
let(:payload) { build(:users_payload) }
let(:response) { subject.create(payload) }
it { expect(response).to be_success }
end
end

View File

@ -2,8 +2,14 @@
FactoryBot.define do
factory :users_payload, class: Hash do
email { 'foo@bar.com' }
email { "btcpaygem-#{SecureRandom.hex}@spec.com" }
password { 'password' }
isAdministrator { false }
initialize_with do
user = {}
attributes.each { |k, v| user[k] = v }
user
end
end
end

9
spec/factories/client.rb Normal file
View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
FactoryBot.define do
factory :client, class: BtcPay::Client::Base do
config factory: :config
initialize_with { new(**attributes) }
end
end

View File

@ -15,7 +15,7 @@ FactoryBot.define do
trait :basic_auth_token do
auth_token { nil }
basic_auth_token { 'TODO' }
basic_auth_token { 'G7Uvk0VV7BWQQI7LrihMnDGhEnR7kopW0PRoli77Lyo' }
end
end
end

View File

@ -21,4 +21,8 @@ RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.before(:each) do
allow(Logger).to receive(:new).and_return(double('Logger', debug: nil, error: nil, warn: nil))
end
end

View File

@ -3,6 +3,7 @@
require 'vcr'
VCR.configure do |config|
config.cassette_library_dir = 'cassettes'
config.cassette_library_dir = 'spec/cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
end