-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update /usage API to latest version (#27)
- Loading branch information
Showing
7 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
graphql-hive (0.4.0) | ||
graphql-hive (0.4.1) | ||
graphql (>= 2.3, < 3) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: ../.. | ||
specs: | ||
graphql-hive (0.4.0) | ||
graphql-hive (0.4.1) | ||
graphql (>= 2.3, < 3) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Graphql | ||
module Hive | ||
VERSION = '0.4.0' | ||
VERSION = '0.4.1' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'graphql-hive' | ||
|
||
RSpec.describe GraphQL::Hive::Client do | ||
let(:options) do | ||
{ | ||
endpoint: 'app.graphql-hive.com', | ||
port: 443, | ||
token: 'Bearer test-token', | ||
logger: Logger.new(nil) | ||
} | ||
end | ||
|
||
let(:client) { described_class.new(options) } | ||
let(:body) { { size: 3, map: {}, operations: [] } } | ||
|
||
describe '#initialize' do | ||
it 'sets the instance' do | ||
expect(client.instance_variable_get(:@options)).to eq(options) | ||
end | ||
end | ||
|
||
describe '#send' do | ||
let(:http) { instance_double(Net::HTTP) } | ||
let(:request) { instance_double(Net::HTTP::Post) } | ||
let(:response) { instance_double(Net::HTTPOK, body: '', code: '200') } | ||
|
||
before do | ||
allow(Net::HTTP).to receive(:new).and_return(http) | ||
allow(Net::HTTP::Post).to receive(:new).and_return(request) | ||
|
||
allow(http).to receive(:use_ssl=) | ||
allow(http).to receive(:read_timeout=) | ||
allow(http).to receive(:request).and_return(response) | ||
|
||
allow(request).to receive(:[]=) # request['header-name'] = 'header-value' | ||
allow(request).to receive(:body=) | ||
end | ||
|
||
it 'sets up the HTTP session' do | ||
expect(Net::HTTP).to receive(:new).with('app.graphql-hive.com', 443).and_return(http) | ||
expect(http).to receive(:use_ssl=).with(true) | ||
expect(http).to receive(:read_timeout=).with(2) | ||
|
||
client.send('/usage', body, :usage) | ||
end | ||
|
||
it 'creates the request with the correct headers and body' do | ||
expect(Net::HTTP::Post).to receive(:new).with('/usage').and_return(request) | ||
expect(request).to receive(:[]=).with('Authorization', 'Bearer test-token') | ||
expect(request).to receive(:[]=).with('X-Usage-API-Version', '2') | ||
expect(request).to receive(:[]=).with('content-type', 'application/json') | ||
expect(request).to receive(:[]=).with('User-Agent', "Hive@#{Graphql::Hive::VERSION}") | ||
expect(request).to receive(:[]=).with('graphql-client-name', 'Hive Ruby Client') | ||
expect(request).to receive(:[]=).with('graphql-client-version', Graphql::Hive::VERSION) | ||
expect(request).to receive(:body=).with(JSON.generate(body)) | ||
|
||
client.send('/usage', body, :usage) | ||
end | ||
|
||
it 'executes the request' do | ||
expect(http).to receive(:request).with(request).and_return(response) | ||
client.send('/usage', body, :usage) | ||
end | ||
|
||
it 'logs a fatal error and raises an exception when an exception is raised' do | ||
allow(http).to receive(:request).and_raise(StandardError.new('Network error')) | ||
expect(options[:logger]).to receive(:fatal).with('Failed to send data: Network error') | ||
expect { client.send('/usage', body, :usage) }.to raise_error(StandardError, 'Network error') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters