Sha256: 47d2dbce74d82c956e13e9ebc2738bbc0991d90f287f7c714838cb3d418b8c44

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 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_private_message' do
    before do
      stub_post("#{host}/posts")
      subject.create_private_message(
        title: "Confidential: Hello World!",
        raw: "This is the raw markdown for my private message",
        target_usernames: "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_usernames=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
        ).to have_been_made
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
discourse_api-0.46.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.45.1 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.45.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.44.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.43.1 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.43.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.42.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.41.0 spec/discourse_api/api/private_messages_spec.rb
discourse_api-0.40.0 spec/discourse_api/api/private_messages_spec.rb