This repository has been archived by the owner on May 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from allolex/feature/nominal-codes
Add nominal code resource support
- Loading branch information
Showing
8 changed files
with
340 additions
and
0 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
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,42 @@ | ||
require "nacre/abstract_resource" | ||
require "nacre/concerns/searchable" | ||
|
||
module Nacre | ||
class NominalCode < AbstractResource | ||
|
||
extend Searchable | ||
extend Getable | ||
|
||
attribute :active | ||
attribute :bank | ||
attribute :chart_map_code | ||
attribute :code | ||
attribute :description | ||
attribute :discount | ||
attribute :editable | ||
attribute :expense | ||
attribute :id | ||
attribute :name | ||
attribute :reconcile | ||
attribute :tax_code | ||
attribute :type | ||
|
||
def self.resource_class | ||
self | ||
end | ||
|
||
def self.resource_name | ||
"nominal-code" | ||
end | ||
|
||
private | ||
|
||
def self.service_name | ||
"accounting" | ||
end | ||
|
||
def self.request_options | ||
"" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "nacre/abstract_resource_collection" | ||
|
||
module Nacre | ||
class NominalCodeCollection < AbstractResourceCollection | ||
|
||
private | ||
|
||
def self.resource_class | ||
NominalCode | ||
end | ||
|
||
def self.request_options | ||
nil | ||
end | ||
|
||
def self.service_name | ||
"accounting" | ||
end | ||
|
||
def self.resource_name | ||
"nominal-code" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require "spec_helper" | ||
|
||
describe Nacre::NominalCodeCollection do | ||
|
||
let!(:link) { Nacre::Connection.new } | ||
|
||
let(:parametrized_list) do | ||
[ | ||
{ | ||
id: 1, | ||
name: "First Code", | ||
code: "1000" | ||
}, | ||
{ | ||
id: 2, | ||
name: "Second Code", | ||
code: "2000" | ||
} | ||
] | ||
end | ||
|
||
let(:subject) { described_class.new(parametrized_list) } | ||
|
||
it_behaves_like "Enumerable" | ||
|
||
context "initialization" do | ||
describe ".new" do | ||
it "should create a list of NominalCodes" do | ||
expect(subject.first).to be_a(Nacre::NominalCode) | ||
end | ||
end | ||
|
||
describe ".from_json" do | ||
let(:json) { fixture_file_content("nominal_code_collection.json") } | ||
let(:subject) { described_class.from_json(json) } | ||
|
||
it "should be a list of NominalCodes" do | ||
expect(subject.first).to be_a(Nacre::NominalCode) | ||
end | ||
end | ||
end | ||
|
||
describe ".get" do | ||
let(:range) { "1-3" } | ||
|
||
let(:get_options) do | ||
{ | ||
search_url: nominal_code_service_url, | ||
ids: range | ||
} | ||
end | ||
|
||
before do | ||
@url = Nacre::RequestUrl.new(get_options) | ||
stub_request( | ||
:get, | ||
@url.to_s | ||
).to_return( | ||
status: 200, | ||
body: fixture_file_content("nominal_code_collection.json"), | ||
headers: {} | ||
) | ||
@collection = Nacre::NominalCodeCollection.get(range) | ||
end | ||
|
||
it "should query the API server" do | ||
expect(a_request(:get, @url.to_s)).to have_been_made | ||
end | ||
|
||
it "should return a valid NominalCodeCollection" do | ||
expect(@collection).to be_a(Nacre::NominalCodeCollection) | ||
end | ||
|
||
it "should contain the fixture nominal_codes" do | ||
expect(@collection.first).to be_a(Nacre::NominalCode) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
|
||
require "spec_helper" | ||
|
||
describe Nacre::NominalCode do | ||
|
||
let!(:link) { Nacre::Connection.new } | ||
|
||
let(:params) do | ||
{ | ||
id: 1, | ||
code: "0010", | ||
name: "Freehold Property", | ||
type: { | ||
id: 1 | ||
}, | ||
bank: false, | ||
expense: false, | ||
discount: false, | ||
editable: true, | ||
active: true, | ||
tax_code: 0, | ||
description: "", | ||
chart_map_code: "", | ||
reconcile: false | ||
} | ||
end | ||
|
||
subject { described_class.new(params) } | ||
|
||
it_behaves_like "Parametrizable" | ||
|
||
context "initialization" do | ||
|
||
describe ".new" do | ||
it "should have an id" do | ||
expect(subject.id).to eq params[:id] | ||
end | ||
|
||
it "should have a name" do | ||
expect(subject.name).to eq params[:name] | ||
end | ||
end | ||
|
||
describe ".from_json" do | ||
let(:json) { fixture_file_content("nominal_code.json") } | ||
|
||
subject { described_class.from_json(json) } | ||
|
||
it "has the correct id" do | ||
expect(subject.id).to eq 1 | ||
end | ||
|
||
it "has the correct name" do | ||
expect(subject.name).to eq "Freehold Property" | ||
end | ||
|
||
it "has the correct code" do | ||
expect(subject.code).to eq "0010" | ||
end | ||
|
||
it "has the correct bank value" do | ||
expect(subject.bank).to eq false | ||
end | ||
|
||
it "has the correct tax code" do | ||
expect(subject.tax_code).to eq 0 | ||
end | ||
|
||
it "has the correct default price list ID" do | ||
expect(subject.chart_map_code).to eq "" | ||
end | ||
end | ||
end | ||
|
||
context "API interactions" do | ||
let!(:link) { Nacre::Connection.new } | ||
|
||
let(:resource) { "accounting" } | ||
|
||
let(:api_details) do | ||
[ | ||
Nacre.configuration.api_version, | ||
Nacre.configuration.user_id | ||
] | ||
end | ||
|
||
describe ".get" do | ||
let(:resource_endpoint) { | ||
nominal_code_service_url | ||
} | ||
|
||
let(:range) { 1 } | ||
|
||
it "should make a request to the correct endpoint" do | ||
stub_request(:get, "#{resource_endpoint}/#{range}"). | ||
to_return( | ||
status: 200, | ||
body: fixture_file_content("nominal_code.json"), | ||
headers: {} | ||
) | ||
|
||
nominal_code = described_class.get(range) | ||
|
||
expect(a_request( | ||
:get, | ||
"#{resource_endpoint}/#{range}" | ||
)).to have_been_made | ||
|
||
expect(nominal_code.id).to eql(range) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"response": [ | ||
{ | ||
"id": 1, | ||
"code": "0010", | ||
"name": "Freehold Property", | ||
"type": { | ||
"id": 1 | ||
}, | ||
"bank": false, | ||
"expense": false, | ||
"discount": false, | ||
"editable": true, | ||
"active": true, | ||
"taxCode": 0, | ||
"description": "", | ||
"chartMapCode": "", | ||
"reconcile": false | ||
} | ||
] | ||
} |
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,55 @@ | ||
{ | ||
"response": [ | ||
{ | ||
"id": 1, | ||
"code": "0010", | ||
"name": "Freehold Property", | ||
"type": { | ||
"id": 1 | ||
}, | ||
"bank": false, | ||
"expense": false, | ||
"discount": false, | ||
"editable": true, | ||
"active": true, | ||
"taxCode": 0, | ||
"description": "", | ||
"chartMapCode": "", | ||
"reconcile": false | ||
}, | ||
{ | ||
"id": 2, | ||
"code": "0011", | ||
"name": "Leasehold Property", | ||
"type": { | ||
"id": 1 | ||
}, | ||
"bank": false, | ||
"expense": false, | ||
"discount": false, | ||
"editable": true, | ||
"active": true, | ||
"taxCode": 0, | ||
"description": "", | ||
"chartMapCode": "", | ||
"reconcile": false | ||
}, | ||
{ | ||
"id": 3, | ||
"code": "0020", | ||
"name": "Plant and Machinery", | ||
"type": { | ||
"id": 1 | ||
}, | ||
"bank": false, | ||
"expense": false, | ||
"discount": false, | ||
"editable": true, | ||
"active": true, | ||
"taxCode": 0, | ||
"description": "", | ||
"chartMapCode": "", | ||
"reconcile": false | ||
} | ||
] | ||
} |
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