Skip to content

Commit

Permalink
code lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ryd994 committed Jul 10, 2023
1 parent 08d075b commit 3244310
Showing 1 changed file with 74 additions and 74 deletions.
148 changes: 74 additions & 74 deletions spec/lib/affiliate_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
# frozen_string_literal: true

require "rails_helper"

describe AffiliateProcessor do
def r(url)
AffiliateProcessor.apply(url)
end

it "can apply affiliate code to ldlc" do
SiteSetting.affiliate_ldlc_com = "samsshop"

expect(r("http://www.ldlc.com/some_product?xyz=1")).to eq(
"http://www.ldlc.com/some_product?xyz=1#samsshop",
)
expect(r("https://ldlc.com/some_product?xyz=1")).to eq(
"https://ldlc.com/some_product?xyz=1#samsshop",
)
end

it "can apply affiliate code correctly to amazon" do
SiteSetting.affiliate_amazon_com = "sams-shop"
SiteSetting.affiliate_amazon_ca = "ca-sams-shop"
SiteSetting.affiliate_amazon_com_au = "au-sams-shop"

expect(r("https://www.amazon.com")).to eq("https://www.amazon.com?tag=sams-shop")
expect(r("http://www.amazon.com/some_product?xyz=1")).to eq(
"http://www.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com/some_product?xyz=1")).to eq(
"https://www.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com?hello=1&tag=bobs-shop")).to eq(
"https://www.amazon.com?tag=sams-shop",
)
expect(r("https://amzn.com/some_product?xyz=1")).to eq(
"https://amzn.com/some_product?tag=sams-shop",
)
expect(r("https://smile.amazon.com/some_product?xyz=1")).to eq(
"https://smile.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com.au/some_product?xyz=1")).to eq(
"https://www.amazon.com.au/some_product?tag=au-sams-shop",
)
expect(
r(
"https://www.amazon.ca/Dragon-Quest-Echoes-Elusive-Age-PlayStation/dp/B07BP3J6RG/ref=br_asw_pdt-5?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=&pf_rd_r=XFGPRSG0SVD5K3RKX5T3&pf_rd_t=36701&pf_rd_p=f8585743-c043-4665-80a7-0cc5fe97d596&pf_rd_i=desktop&th=1",
),
).to eq(
"https://www.amazon.ca/Dragon-Quest-Echoes-Elusive-Age-PlayStation/dp/B07BP3J6RG/ref=br_asw_pdt-5?tag=ca-sams-shop",
)

# keep node (BrowseNodeSearch) query parameter
expect(r("https://www.amazon.com/b?ie=UTF8&node=13548845011")).to eq(
"https://www.amazon.com/b?tag=sams-shop&node=13548845011",
)
# keep nodeId for help pages
expect(r("https://www.amazon.com/gp/help/customer/display.html?nodeId=GENAFPTNLHV7ZACW")).to eq(
"https://www.amazon.com/gp/help/customer/display.html?tag=sams-shop&nodeId=GENAFPTNLHV7ZACW",
)
end

it "can apply codes to post in post processor" do
SiteSetting.queue_jobs = false
SiteSetting.affiliate_amazon_com = "sams-shop"

stub_request(:get, "http://www.amazon.com/link?testing").to_return(status: 200, body: "")
post = create_post(raw: "this is an www.amazon.com/link?testing yay")
post.reload

expect(post.cooked.scan("sams-shop").length).to eq(1)
end
end
# frozen_string_literal: true

require "rails_helper"

describe AffiliateProcessor do
def r(url)
AffiliateProcessor.apply(url)
end

it "can apply affiliate code to ldlc" do
SiteSetting.affiliate_ldlc_com = "samsshop"

expect(r("http://www.ldlc.com/some_product?xyz=1")).to eq(
"http://www.ldlc.com/some_product?xyz=1#samsshop",
)
expect(r("https://ldlc.com/some_product?xyz=1")).to eq(
"https://ldlc.com/some_product?xyz=1#samsshop",
)
end

it "can apply affiliate code correctly to amazon" do
SiteSetting.affiliate_amazon_com = "sams-shop"
SiteSetting.affiliate_amazon_ca = "ca-sams-shop"
SiteSetting.affiliate_amazon_com_au = "au-sams-shop"

expect(r("https://www.amazon.com")).to eq("https://www.amazon.com?tag=sams-shop")
expect(r("http://www.amazon.com/some_product?xyz=1")).to eq(
"http://www.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com/some_product?xyz=1")).to eq(
"https://www.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com?hello=1&tag=bobs-shop")).to eq(
"https://www.amazon.com?tag=sams-shop",
)
expect(r("https://amzn.com/some_product?xyz=1")).to eq(
"https://amzn.com/some_product?tag=sams-shop",
)
expect(r("https://smile.amazon.com/some_product?xyz=1")).to eq(
"https://smile.amazon.com/some_product?tag=sams-shop",
)
expect(r("https://www.amazon.com.au/some_product?xyz=1")).to eq(
"https://www.amazon.com.au/some_product?tag=au-sams-shop",
)
expect(
r(
"https://www.amazon.ca/Dragon-Quest-Echoes-Elusive-Age-PlayStation/dp/B07BP3J6RG/ref=br_asw_pdt-5?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=&pf_rd_r=XFGPRSG0SVD5K3RKX5T3&pf_rd_t=36701&pf_rd_p=f8585743-c043-4665-80a7-0cc5fe97d596&pf_rd_i=desktop&th=1",
),
).to eq(
"https://www.amazon.ca/Dragon-Quest-Echoes-Elusive-Age-PlayStation/dp/B07BP3J6RG/ref=br_asw_pdt-5?tag=ca-sams-shop",
)

# keep node (BrowseNodeSearch) query parameter
expect(r("https://www.amazon.com/b?ie=UTF8&node=13548845011")).to eq(
"https://www.amazon.com/b?tag=sams-shop&node=13548845011",
)

# keep nodeId for help pages
expect(r("https://www.amazon.com/gp/help/customer/display.html?nodeId=GENAFPTNLHV7ZACW")).to eq(
"https://www.amazon.com/gp/help/customer/display.html?tag=sams-shop&nodeId=GENAFPTNLHV7ZACW",
)
end

it "can apply codes to post in post processor" do
SiteSetting.queue_jobs = false
SiteSetting.affiliate_amazon_com = "sams-shop"

stub_request(:get, "http://www.amazon.com/link?testing").to_return(status: 200, body: "")
post = create_post(raw: "this is an www.amazon.com/link?testing yay")
post.reload

expect(post.cooked.scan("sams-shop").length).to eq(1)
end
end

0 comments on commit 3244310

Please sign in to comment.