summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThomas Balthazar <thomas@balthazar.info>2016-08-10 12:25:01 +0200
committerThomas Balthazar <thomas@balthazar.info>2016-08-11 08:52:13 +0200
commitfb748daf538e43efcf8884f017391bcbfccf2ea2 (patch)
treec94ec042e25eaf630008dab7f2f57d6da175a949 /spec
parent551ffc0a4d25a381e9f8f6a8d6f2793bb87f3145 (diff)
downloadgitlab-ce-fb748daf538e43efcf8884f017391bcbfccf2ea2.tar.gz
Replace the tinder gem by bare HTTP requests
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/project_services/campfire/rooms.json22
-rw-r--r--spec/fixtures/project_services/campfire/rooms2.json22
-rw-r--r--spec/models/project_services/campfire_service_spec.rb58
3 files changed, 102 insertions, 0 deletions
diff --git a/spec/fixtures/project_services/campfire/rooms.json b/spec/fixtures/project_services/campfire/rooms.json
new file mode 100644
index 00000000000..71e9645c955
--- /dev/null
+++ b/spec/fixtures/project_services/campfire/rooms.json
@@ -0,0 +1,22 @@
+{
+ "rooms": [
+ {
+ "name": "test-room",
+ "locked": false,
+ "created_at": "2009/01/07 20:43:11 +0000",
+ "updated_at": "2009/03/18 14:31:39 +0000",
+ "topic": "The room topic\n",
+ "id": 123,
+ "membership_limit": 4
+ },
+ {
+ "name": "another room",
+ "locked": true,
+ "created_at": "2009/03/18 14:30:42 +0000",
+ "updated_at": "2013/01/27 14:14:27 +0000",
+ "topic": "Comment, ideas, GitHub notifications for eCommittee App",
+ "id": 456,
+ "membership_limit": 4
+ }
+ ]
+}
diff --git a/spec/fixtures/project_services/campfire/rooms2.json b/spec/fixtures/project_services/campfire/rooms2.json
new file mode 100644
index 00000000000..3d5f635d8b3
--- /dev/null
+++ b/spec/fixtures/project_services/campfire/rooms2.json
@@ -0,0 +1,22 @@
+{
+ "rooms": [
+ {
+ "name": "test-room-not-found",
+ "locked": false,
+ "created_at": "2009/01/07 20:43:11 +0000",
+ "updated_at": "2009/03/18 14:31:39 +0000",
+ "topic": "The room topic\n",
+ "id": 123,
+ "membership_limit": 4
+ },
+ {
+ "name": "another room",
+ "locked": true,
+ "created_at": "2009/03/18 14:30:42 +0000",
+ "updated_at": "2013/01/27 14:14:27 +0000",
+ "topic": "Comment, ideas, GitHub notifications for eCommittee App",
+ "id": 456,
+ "membership_limit": 4
+ }
+ ]
+}
diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb
index 3e6da42803b..1adf93258f3 100644
--- a/spec/models/project_services/campfire_service_spec.rb
+++ b/spec/models/project_services/campfire_service_spec.rb
@@ -39,4 +39,62 @@ describe CampfireService, models: true do
it { is_expected.not_to validate_presence_of(:token) }
end
end
+
+ describe "#execute" do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ before do
+ @campfire_service = CampfireService.new
+ allow(@campfire_service).to receive_messages(
+ project_id: project.id,
+ project: project,
+ service_hook: true,
+ token: 'verySecret',
+ subdomain: 'project-name',
+ room: 'test-room'
+ )
+ @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
+ @rooms_url = 'https://verySecret:X@project-name.campfirenow.com/rooms.json'
+ @headers = { 'Content-Type' => 'application/json; charset=utf-8' }
+ end
+
+ it "calls Campfire API to get a list of rooms and speak in a room" do
+ # make sure a valid list of rooms is returned
+ body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms.json')
+ WebMock.stub_request(:get, @rooms_url).to_return(
+ body: body,
+ status: 200,
+ headers: @headers
+ )
+ # stub the speak request with the room id found in the previous request's response
+ speak_url = 'https://verySecret:X@project-name.campfirenow.com/room/123/speak.json'
+ WebMock.stub_request(:post, speak_url)
+
+ @campfire_service.execute(@sample_data)
+
+ expect(WebMock).to have_requested(:get, @rooms_url).once
+ expect(WebMock).to have_requested(:post, speak_url).with(
+ body: /#{project.path}.*#{@sample_data[:before]}.*#{@sample_data[:after]}/
+ ).once
+ end
+
+ it "calls Campfire API to get a list of rooms but shouldn't speak in a room" do
+ # return a list of rooms that do not contain a room named 'test-room'
+ body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms2.json')
+ WebMock.stub_request(:get, @rooms_url).to_return(
+ body: body,
+ status: 200,
+ headers: @headers
+ )
+ # we want to make sure no request is sent to the /speak endpoint, here is a basic
+ # regexp that matches this endpoint
+ speak_url = 'https://verySecret:X@project-name.campfirenow.com/room/.*/speak.json'
+
+ @campfire_service.execute(@sample_data)
+
+ expect(WebMock).to have_requested(:get, @rooms_url).once
+ expect(WebMock).not_to have_requested(:post, /#{speak_url}/)
+ end
+ end
end