Sha256: 2398e065ed794781b1058780bd7f800814ff1089038e2b955e7532f264b60f23

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true
require "spec_helper"

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

  describe "#badges" do
    before do
      stub_get("#{host}/admin/badges.json").to_return(
        body: fixture("badges.json"),
        headers: {
          content_type: "application/json",
        },
      )
    end

    it "requests the correct resource" do
      subject.badges
      expect(a_get("#{host}/admin/badges.json")).to have_been_made
    end

    it "returns the requested badges" do
      badges = subject.badges
      expect(badges).to be_a Hash
      expect(badges["badges"]).to be_an Array
    end
  end

  describe "#user-badges" do
    before do
      stub_get("#{host}/user-badges/test_user.json").to_return(
        body: fixture("user_badges.json"),
        headers: {
          content_type: "application/json",
        },
      )
    end

    it "requests the correct resource" do
      subject.user_badges("test_user")
      expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
    end

    it "returns the requested user badges" do
      badges = subject.user_badges("test_user")
      expect(badges).to be_an Array
      expect(badges.first).to be_a Hash
      expect(badges.first).to have_key("badge_type_id")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discourse_api-2.0.1 spec/discourse_api/api/badges_spec.rb
discourse_api-2.0.0 spec/discourse_api/api/badges_spec.rb