|
1 | 1 | # frozen_string_literal: true |
2 | | -require "rails_helper" |
3 | 2 |
|
4 | | -RSpec.describe "Consyncful::WebhookController", type: :request do |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +RSpec.describe 'Consyncful::WebhookController', type: :request do |
5 | 6 | let(:config) do |
6 | 7 | # Provide a simple configuration double with the fields used by the controller |
7 | 8 | instance_double( |
8 | | - "Consyncful::Configuration", |
| 9 | + 'Consyncful::Configuration', |
9 | 10 | sync_mode: sync_mode, |
10 | 11 | webhook_authentication_required: auth_required, |
11 | | - webhook_user: "user1", |
12 | | - webhook_password: "secret" |
| 12 | + webhook_user: 'user1', |
| 13 | + webhook_password: 'secret' |
13 | 14 | ) |
14 | 15 | end |
15 | 16 |
|
16 | 17 | before do |
17 | 18 | allow(Consyncful).to receive(:configuration).and_return(config) |
18 | 19 | end |
19 | 20 |
|
20 | | - describe "POST /consyncful/webhook" do |
21 | | - subject(:perform) { post "/consyncful/webhook", headers: headers } |
| 21 | + describe 'POST /consyncful/webhook' do |
| 22 | + subject(:perform) { post '/consyncful/webhook', headers: headers } |
22 | 23 |
|
23 | 24 | let(:headers) { {} } |
24 | 25 |
|
25 | | - context "when sync mode is not :webhook" do |
| 26 | + context 'when sync mode is not :webhook' do |
26 | 27 | let(:sync_mode) { :poll } |
27 | 28 | let(:auth_required) { false } |
28 | 29 |
|
29 | | - it "returns 404 Not Found" do |
| 30 | + it 'returns 404 Not Found' do |
30 | 31 | perform |
31 | 32 | expect(response).to have_http_status(:not_found) |
32 | 33 | end |
33 | 34 | end |
34 | 35 |
|
35 | | - context "when sync mode is :webhook" do |
| 36 | + context 'when sync mode is :webhook' do |
36 | 37 | let(:sync_mode) { :webhook } |
37 | 38 |
|
38 | | - context "and authentication is not required" do |
| 39 | + context 'and authentication is not required' do |
39 | 40 | let(:auth_required) { false } |
40 | 41 |
|
41 | | - it "signals the sync and returns 202 Accepted" do |
| 42 | + it 'signals the sync and returns 202 Accepted' do |
42 | 43 | expect(Consyncful::Sync).to receive(:signal_webhook!) |
43 | 44 | perform |
44 | 45 | expect(response).to have_http_status(:accepted) |
45 | 46 | end |
46 | 47 | end |
47 | 48 |
|
48 | | - context "and authentication is required" do |
| 49 | + context 'and authentication is required' do |
49 | 50 | let(:auth_required) { true } |
50 | 51 |
|
51 | | - context "with no credentials" do |
52 | | - it "returns 401 Unauthorized" do |
| 52 | + context 'with no credentials' do |
| 53 | + it 'returns 401 Unauthorized' do |
53 | 54 | perform |
54 | 55 | expect(response).to have_http_status(:unauthorized) |
55 | 56 | end |
56 | 57 | end |
57 | 58 |
|
58 | | - context "with wrong credentials" do |
| 59 | + context 'with wrong credentials' do |
59 | 60 | let(:headers) do |
60 | 61 | { |
61 | | - "HTTP_AUTHORIZATION" => |
62 | | - ActionController::HttpAuthentication::Basic.encode_credentials("user1", "wrong") |
| 62 | + 'HTTP_AUTHORIZATION' => |
| 63 | + ActionController::HttpAuthentication::Basic.encode_credentials('user1', 'wrong') |
63 | 64 | } |
64 | 65 | end |
65 | 66 |
|
66 | | - it "returns 401 Unauthorized" do |
| 67 | + it 'returns 401 Unauthorized' do |
67 | 68 | perform |
68 | 69 | expect(response).to have_http_status(:unauthorized) |
69 | 70 | end |
70 | 71 | end |
71 | 72 |
|
72 | | - context "with correct credentials" do |
| 73 | + context 'with correct credentials' do |
73 | 74 | let(:headers) do |
74 | 75 | { |
75 | | - "HTTP_AUTHORIZATION" => |
76 | | - ActionController::HttpAuthentication::Basic.encode_credentials("user1", "secret") |
| 76 | + 'HTTP_AUTHORIZATION' => |
| 77 | + ActionController::HttpAuthentication::Basic.encode_credentials('user1', 'secret') |
77 | 78 | } |
78 | 79 | end |
79 | 80 |
|
80 | | - it "signals the sync and returns 202 Accepted" do |
| 81 | + it 'signals the sync and returns 202 Accepted' do |
81 | 82 | expect(Consyncful::Sync).to receive(:signal_webhook!) |
82 | 83 | perform |
83 | 84 | expect(response).to have_http_status(:accepted) |
|
0 commit comments