Sha256: aca90958b1da4a56c504a2d399f4173aec9011a73d37f249fa64b82c1dedf67a

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe DiscourseApi::API::PrivateMessages do
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }

  describe "#private_messages" do
    before do
      stub_get("#{host}/topics/private-messages/test_user.json").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
    end

    it "requests the correct resource" do
      subject.private_messages('test_user')
      expect(a_get("#{host}/topics/private-messages/test_user.json")).to have_been_made
    end

    it "returns the requested private messages" do
      private_messages = subject.private_messages('test_user')
      expect(private_messages).to be_an Array
    end
  end

  describe "#sent_private_messages" do
    before do
      stub_get("#{host}/topics/private-messages-sent/test_user.json").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
    end

    it "requests the correct resource" do
      subject.sent_private_messages('test_user')
      expect(a_get("#{host}/topics/private-messages-sent/test_user.json")).to have_been_made
    end

    it "returns the requested sent private messages" do
      private_messages = subject.sent_private_messages('test_user')
      expect(private_messages).to be_an Array
    end
  end

  describe '#create_pm' do
    before do
      stub_post("#{host}/posts")
      subject.create_pm(
        title: "Confidential: Hello World!",
        raw: "This is the raw markdown for my private message",
        target_recipients: "user1,user2"
      )
    end

    it "makes a create private message request" do
      expect(a_post("#{host}/posts").with(body:
          'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_recipients=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
        ).to have_been_made
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
discourse_api-1.1.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-1.0.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.48.1 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.48.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.47.0 spec/discourse_api/api/private_messages_spec.rb