Skip to content

Commit b6117d6

Browse files
Added test cases for region support and include_metadata
1 parent a86cb94 commit b6117d6

File tree

6 files changed

+54
-16
lines changed

6 files changed

+54
-16
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
contentstack (0.6.4)
4+
contentstack (0.7.0)
55
activesupport (>= 3.2)
66
contentstack_utils (~> 1.0)
77

lib/contentstack/client.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ def sync(params)
8181

8282
private
8383
def get_default_region_hosts(region='us')
84-
host = "https://cdn.contentstack.io" #set default host if region is nil
84+
host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" #set default host if region is nil
8585
case region
8686
when "us"
87-
host = "https://cdn.contentstack.io"
87+
host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}"
8888
when "eu"
89-
host = "https://eu-cdn.contentstack.com"
89+
host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{Contentstack::Region::HOST}"
9090
when "azure-na"
91-
host = "https://azure-na-cdn.contentstack.com"
91+
host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{Contentstack::Region::HOST}"
9292
when "azure-eu"
93-
host = "https://azure-eu-cdn.contentstack.com"
93+
host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{Contentstack::Region::HOST}"
9494
end
9595
host
9696
end
@@ -102,19 +102,19 @@ def get_host_by_region(region, options)
102102
custom_host = options[:host]
103103
case region
104104
when "us"
105-
host = "https://cdn.#{custom_host}"
105+
host = "#{Contentstack::Region::PROTOCOL}://cdn.#{custom_host}"
106106
when "eu"
107-
host = "https://eu-cdn.#{custom_host}"
107+
host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{custom_host}"
108108
when "azure-na"
109-
host = "https://azure-na-cdn.#{custom_host}"
109+
host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{custom_host}"
110110
when "azure-eu"
111-
host = "https://azure-eu-cdn.#{custom_host}"
111+
host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{custom_host}"
112112
end
113113
elsif options[:host].present? && region.empty?
114114
custom_host = options[:host]
115-
host = "https://cdn.#{custom_host}"
115+
host = "#{Contentstack::Region::PROTOCOL}://cdn.#{custom_host}"
116116
else
117-
host = "https://cdn.contentstack.io" #set default host if region and host is empty
117+
host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" #set default host if region and host is empty
118118
end
119119
host
120120
end

lib/contentstack/region.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ class Region
44
US='us'
55
AZURE_NA='azure-na'
66
AZURE_EU='azure-eu'
7+
PROTOCOL='https'
8+
DEFAULT_HOST='cdn.contentstack.io'
9+
HOST='contentstack.com'
710
end
811
end

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.6.4"
2+
VERSION = "0.7.0"
33
end

spec/contentstack_spec.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
describe Contentstack do
55
let(:client) { create_client }
66
let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
7-
let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
7+
let(:azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_NA}) }
8+
let(:azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_EU}) }
9+
let(:custom_host_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::EU}) }
10+
let(:custom_host_azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_EU}) }
11+
let(:custom_host_azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_NA}) }
812

913
it "has a version number" do
1014
expect(Contentstack::VERSION).not_to be nil
@@ -13,6 +17,8 @@
1317
it "has region data" do
1418
expect(Contentstack::Region::EU).not_to be 'eu'
1519
expect(Contentstack::Region::US).not_to be 'us'
20+
expect(Contentstack::Region::AZURE_NA).not_to be 'azure-na'
21+
expect(Contentstack::Region::AZURE_EU).not_to be 'azure-eu'
1622
end
1723

1824
it "has default host and region" do
@@ -25,10 +31,29 @@
2531
expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
2632
end
2733

28-
it "has custom host" do
29-
expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com'
34+
it "has custom region with region host" do
35+
expect(azure_na_client.region).to eq Contentstack::Region::AZURE_NA
36+
expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
37+
end
38+
39+
it "has custom region with region host" do
40+
expect(azure_eu_client.region).to eq Contentstack::Region::AZURE_EU
41+
expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
42+
end
43+
44+
it "has custom host and eu region" do
45+
expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com'
3046
end
3147

48+
it "has custom host and azure-eu region" do
49+
expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
50+
end
51+
52+
it "has custom host and azure-na region" do
53+
expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
54+
end
55+
56+
3257
it "JSON to HTML" do
3358
expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq ''
3459
end

spec/entry_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
data = category.include_metadata.fetch
9393
expect(data.content_type).not_to be nil
9494
end
95+
96+
it "should get data using `include_metadata` method with param false" do
97+
data = category.include_metadata(false).fetch
98+
expect(data.content_type).not_to be nil
99+
end
100+
101+
it "should get data using `include_metadata` method with param true" do
102+
data = category.include_metadata(true).fetch
103+
expect(data.content_type).not_to be nil
104+
end
95105

96106
it "should get data using `include_reference` method" do
97107
data = product.include_reference('categories').fetch

0 commit comments

Comments
 (0)