spec/databox/client_spec.rb in databox-0.1.2 vs spec/databox/client_spec.rb in databox-0.2.1
- old
+ new
@@ -1,96 +1,53 @@
-require "spec_helper"
+require 'spec_helper'
+require 'pp'
describe Databox::Client do
- let(:client){ Databox.client }
+ before do
+ Databox.configure do |c|
+ c.push_token = 'adxg1kq5a4g04k0wk0s4wkssow8osw84'
+ end
- context "#push" do
+ allow_any_instance_of(Databox::Client).to receive(:raw_push)\
+ .and_return({'status' => 'ok'})
+ end
- context "validation" do
+ let!(:client) { Databox::Client.new }
- it do
- expect {
- client.push()
- }.to raise_error(Databox::InvalidRecord){ |e|
- expect(e.errors).to include "Data is missing"
- }
- end
+ context 'push' do
+ it { expect { client.push(nil) }.to raise_exception }
+ it { expect { client.push(key: 'sales.total', value: nil) }.to raise_exception }
+ it { expect { client.push(key: nil, value: 3000) }.to raise_exception }
+ it { expect(client.push(key: 'sales.total', value: 2000)).to eq true }
+ end
- it do
- expect {
- client.push({})
- }.to raise_error(Databox::InvalidRecord)
- end
-
- it do
- expect {
- client.push({})
- }.to raise_error(Databox::InvalidRecord){ |e|
- expect(e.errors).to include "Key is required"
- # expect(e.errors).to include "Value is required"
- }
- end
-
- it do
- expect {
- client.push({key:" w d d", date:"", value:"Oto was here"})
- }.to raise_error(Databox::InvalidRecord){ |e|
- expect(e.errors).to include "Date format is invalid"
- expect(e.errors).to include "Key format is invalid"
- }
- end
-
- it "validates list" do
- expect {
- client.push([
- {date:"2014-01-29"},
- {key:"what", date:"2014-01-29"}
- ])
- }.to raise_error(Databox::InvalidRecord){ |e|
- expect(e.errors).to include "Key is required"
- }
- end
-
- end
-
- context "valid KPI" do
- before {
- stub_request(:post, /push/).to_return { request_from "simple_push" }
+ context 'push w/ attributes' do
+ it {
+ payload = {
+ key: 'test',
+ value: 200,
+ attributes: {
+ 'me': 'Oto'
+ }
}
- let(:data){ {
- key: "databox_visits",
- date: "2014-01-29",
- value: 1
- } }
-
- let!(:response){ client.push(data) }
-
- it { expect(response).to be_kind_of(Databox::Response) }
- it { expect(response).to be_success }
-
- end
-
- # #TODO: Validation on server is down.
- # context "too many requests" do
- # before {
- # stub_request(:post, /push/).to_return { request_from "invalid_push" }
- # Databox::Client.any_instance.stub(:validate).and_return(true)
- # }
- # let(:data){{
- # key:"o t o",
- # date: "d d d",
- # value: "-2"
- # }}
- # let!(:response){ client.push(data) }
- # it { expect(response).to be_kind_of(Databox::ClientError) }
- # end
-
+ expect(client).to receive(:raw_push)
+ .with('/', [
+ {"$test" => 200, :me => "Oto"}
+ ])
+ .once.and_call_original
+ expect(client.push(payload)).to eq true
+ }
end
- context "#logs" do
- before { stub_request(:get, /logs/).to_return { request_from "logs" } }
- subject { client.logs }
- it { expect(subject).to be_kind_of Array }
- end
+ context 'insert_all' do
+ it { expect { client.insert_all([
+ {key: 'temp.lj'},
+ {key: 'temp.ljx', value: 60.3},
+ ]) }.to raise_exception }
-end
+ it { expect(client.insert_all([
+ {key: 'temp.ljx', value: 4.3},
+ {key: 'temp.ljx', value: 1.3, date: '2015-01-01 09:00:00'},
+ ])).to eq true }
+ end
+end
\ No newline at end of file