spec/desk/client/article_spec.rb in desk-0.3.3 vs spec/desk/client/article_spec.rb in desk-1.0.0
- old
+ new
@@ -1,133 +1,78 @@
require 'helper'
describe Desk::Client do
- Desk::Configuration::VALID_FORMATS.each do |format|
- context ".new(:format => '#{format}')" do
- before do
- @client = Desk::Client.new(:subdomain => "example", :format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
- end
+ context "Article" do
- describe ".articles" do
+ let(:endpoint) { "article" }
+ let(:id) { 1 }
+ let(:check_key) { "subject" }
+ let(:check_value) { "Awesome Subject" }
- context "lookup" do
+ include_context "basic configuration"
- before do
- stub_get("topics/1/articles.#{format}").
- to_return(:body => fixture("articles.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
+ it_behaves_like "a list endpoint"
- it "should post to the correct resource" do
- @client.articles(1)
- a_get("topics/1/articles.#{format}").
- should have_been_made
- end
+ it_behaves_like "a show endpoint"
- it "should return the articles" do
- articles = @client.articles(1)
+ it_behaves_like "a create endpoint", {
+ :subject => "Awesome Subject",
+ :body => "Simply post here",
+ :_links => {
+ :topic => {
+ :href => "/api/v2/topics/1",
+ :class => "topic"
+ }
+ }
+ }
- articles.results.should be_a Array
- articles.results.first.article.id.should == 13
- end
+ it_behaves_like "an update endpoint", {
+ :subject => "How to make your customers happy",
+ :body => "<strong>Use Desk.com</strong>",
+ :body_email => "Custom email body for article",
+ :body_email_auto => false,
+ :_links => {
+ :topic => {
+ :href => "/api/v2/topics/1",
+ :class => "topic"
+ }
+ }
+ } do
+ let(:check_value) { "How to make your customers happy" }
+ end
- end
- end
+ it_behaves_like "a delete endpoint"
- describe ".article" do
+ it_behaves_like "a search endpoint", {
+ :text => "happy",
+ :topic_ids => "1,2,4"
+ }
- context "lookup" do
+ context "Translation" do
- before do
- stub_get("articles/13.#{format}").
- to_return(:body => fixture("article.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
+ let(:sub_endpoint) { "translation" }
+ let(:sub_id) { "en" }
+ let(:check_key) { "subject" }
+ let(:check_value) { "Awesome Subject" }
- it "should get the correct resource" do
- @client.article(13)
- a_get("articles/13.#{format}").
- should have_been_made
- end
+ it_behaves_like "a sub list endpoint"
- it "should return up to 100 cases worth of extended information" do
- article = @client.article(13)
+ it_behaves_like "a sub show endpoint"
- article.id.should == 13
- article.subject.should == "API Tips"
- end
-
- end
+ it_behaves_like "a sub create endpoint", {
+ :locale => "es",
+ :subject => "Spanish Translation",
+ :body => "Traducción español aquí"
+ } do
+ let(:sub_id) { "es" }
+ let(:check_value) { "Spanish Translation" }
end
- describe ".create_article" do
-
- context "create" do
-
- before do
- stub_post("topics/1/articles.#{format}").
- to_return(:body => fixture("article_create.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
-
- it "should post to the correct resource" do
- @client.create_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
- a_post("topics/1/articles.#{format}").
- should have_been_made
- end
-
- it "should return the articles" do
- article = @client.create_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
-
- article.id.should == 13
- end
-
- end
- end
-
- describe ".update_article" do
-
- context "update" do
-
- before do
- stub_put("articles/1.#{format}").
- to_return(:body => fixture("article_update.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
-
- it "should post to the correct resource" do
- @client.update_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
- a_put("articles/1.#{format}").
- should have_been_made
- end
-
- it "should return the new topic" do
- topic = @client.update_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
-
- topic.subject.should == "API Tips"
- topic.main_content.should == "Tips on using our API"
- end
-
- end
- end
-
- describe ".delete_article" do
-
- context "delete" do
-
- before do
- stub_delete("articles/1.#{format}").
- to_return(:body => fixture("article_destroy.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
-
- it "should post to the correct resource" do
- @client.delete_article(1)
- a_delete("articles/1.#{format}").
- should have_been_made
- end
-
- it "should return a successful response" do
- topic = @client.delete_article(1)
- topic.success.should == true
- end
-
- end
+ it_behaves_like "a sub update endpoint", {
+ :subject => "Updated Spanish Translation"
+ } do
+ let(:sub_id) { "es" }
+ let(:check_value) { "Updated Spanish Translation" }
end
end
end
end