|
1257 | 1257 | let(:request_url) { 'https://api.cronofy.com/v1/availability' } |
1258 | 1258 | let(:request_headers) { json_request_headers } |
1259 | 1259 |
|
| 1260 | + let(:client_id) { 'example_id' } |
| 1261 | + let(:client_secret) { 'example_secret' } |
| 1262 | + let(:token) { client_secret } |
| 1263 | + |
| 1264 | + let(:client) do |
| 1265 | + Cronofy::Client.new( |
| 1266 | + client_id: client_id, |
| 1267 | + client_secret: client_secret, |
| 1268 | + ) |
| 1269 | + end |
| 1270 | + |
1260 | 1271 | let(:request_body) do |
1261 | 1272 | { |
1262 | 1273 | "participants" => [ |
|
1770 | 1781 | it_behaves_like 'a Cronofy request' |
1771 | 1782 | it_behaves_like 'a Cronofy request with mapped return value' |
1772 | 1783 | end |
| 1784 | + |
| 1785 | + context "when trying to auth with only an access_token, as originally implemented" do |
| 1786 | + let(:access_token) { "access_token_123"} |
| 1787 | + let(:client) { Cronofy::Client.new(access_token: access_token) } |
| 1788 | + let(:request_headers) do |
| 1789 | + { |
| 1790 | + "Authorization" => "Bearer #{access_token}", |
| 1791 | + "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}", |
| 1792 | + "Content-Type" => "application/json; charset=utf-8", |
| 1793 | + } |
| 1794 | + end |
| 1795 | + |
| 1796 | + let(:participants) do |
| 1797 | + { members: %w{acc_567236000909002 acc_678347111010113} } |
| 1798 | + end |
| 1799 | + |
| 1800 | + let(:required_duration) { 60 } |
| 1801 | + |
| 1802 | + let(:available_periods) do |
| 1803 | + [ |
| 1804 | + { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") }, |
| 1805 | + { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") }, |
| 1806 | + ] |
| 1807 | + end |
| 1808 | + |
| 1809 | + it_behaves_like 'a Cronofy request' |
| 1810 | + it_behaves_like 'a Cronofy request with mapped return value' |
| 1811 | + end |
| 1812 | + |
| 1813 | + context "when trying to auth with both a client_secret and access_token" do |
| 1814 | + let(:access_token) { "access_token_123" } |
| 1815 | + let(:client_secret) { "client_secret_456" } |
| 1816 | + let(:client) { Cronofy::Client.new(access_token: access_token, client_secret: client_secret) } |
| 1817 | + let(:request_headers) do |
| 1818 | + { |
| 1819 | + "Authorization" => "Bearer #{access_token}", |
| 1820 | + "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}", |
| 1821 | + "Content-Type" => "application/json; charset=utf-8", |
| 1822 | + } |
| 1823 | + end |
| 1824 | + |
| 1825 | + let(:participants) do |
| 1826 | + { members: %w{acc_567236000909002 acc_678347111010113} } |
| 1827 | + end |
| 1828 | + |
| 1829 | + let(:required_duration) { 60 } |
| 1830 | + |
| 1831 | + let(:available_periods) do |
| 1832 | + [ |
| 1833 | + { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") }, |
| 1834 | + { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") }, |
| 1835 | + ] |
| 1836 | + end |
| 1837 | + |
| 1838 | + describe "it prefers the access_token for backward compatibility" do |
| 1839 | + it_behaves_like 'a Cronofy request' |
| 1840 | + it_behaves_like 'a Cronofy request with mapped return value' |
| 1841 | + end |
| 1842 | + end |
| 1843 | + |
| 1844 | + context "when trying to auth without a client_secret or access_token" do |
| 1845 | + let(:client) { Cronofy::Client.new } |
| 1846 | + |
| 1847 | + let(:participants) do |
| 1848 | + { members: %w{acc_567236000909002 acc_678347111010113} } |
| 1849 | + end |
| 1850 | + |
| 1851 | + let(:required_duration) { 60 } |
| 1852 | + |
| 1853 | + let(:available_periods) do |
| 1854 | + [ |
| 1855 | + { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") }, |
| 1856 | + { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") }, |
| 1857 | + ] |
| 1858 | + end |
| 1859 | + |
| 1860 | + |
| 1861 | + it "raises an API Key error" do |
| 1862 | + expect{ subject }.to raise_error(Cronofy::CredentialsMissingError) |
| 1863 | + end |
| 1864 | + end |
1773 | 1865 | end |
1774 | 1866 | end |
1775 | 1867 |
|
|
1779 | 1871 | let(:request_url) { 'https://api.cronofy.com/v1/sequenced_availability' } |
1780 | 1872 | let(:request_headers) { json_request_headers } |
1781 | 1873 |
|
| 1874 | + let(:client_id) { 'example_id' } |
| 1875 | + let(:client_secret) { 'example_secret' } |
| 1876 | + let(:token) { client_secret } |
| 1877 | + |
| 1878 | + let(:client) do |
| 1879 | + Cronofy::Client.new( |
| 1880 | + client_id: client_id, |
| 1881 | + client_secret: client_secret, |
| 1882 | + ) |
| 1883 | + end |
| 1884 | + |
1782 | 1885 | let(:request_body) do |
1783 | 1886 | { |
1784 | 1887 | "sequence" => [ |
|
1937 | 2040 | it_behaves_like 'a Cronofy request' |
1938 | 2041 | it_behaves_like 'a Cronofy request with mapped return value' |
1939 | 2042 | end |
| 2043 | + |
| 2044 | + context "when trying to auth with access_token only" do |
| 2045 | + let(:access_token) { "access_token_123"} |
| 2046 | + let(:client) { Cronofy::Client.new(access_token: access_token) } |
| 2047 | + let(:request_headers) do |
| 2048 | + { |
| 2049 | + "Authorization" => "Bearer #{access_token}", |
| 2050 | + "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}", |
| 2051 | + "Content-Type" => "application/json; charset=utf-8", |
| 2052 | + } |
| 2053 | + end |
| 2054 | + |
| 2055 | + it_behaves_like 'a Cronofy request' |
| 2056 | + it_behaves_like 'a Cronofy request with mapped return value' |
| 2057 | + end |
| 2058 | + |
| 2059 | + context "when trying to auth with both access_token and client_secret provided" do |
| 2060 | + let(:client_id) { 'example_id' } |
| 2061 | + let(:client_secret) { 'example_secret' } |
| 2062 | + let(:access_token) { "access_token_123"} |
| 2063 | + |
| 2064 | + let(:client) do |
| 2065 | + Cronofy::Client.new( |
| 2066 | + client_id: client_id, |
| 2067 | + client_secret: client_secret, |
| 2068 | + access_token: access_token, |
| 2069 | + ) |
| 2070 | + end |
| 2071 | + let(:request_headers) do |
| 2072 | + { |
| 2073 | + "Authorization" => "Bearer #{access_token}", |
| 2074 | + "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}", |
| 2075 | + "Content-Type" => "application/json; charset=utf-8", |
| 2076 | + } |
| 2077 | + end |
| 2078 | + |
| 2079 | + it_behaves_like 'a Cronofy request' |
| 2080 | + it_behaves_like 'a Cronofy request with mapped return value' |
| 2081 | + end |
1940 | 2082 | end |
1941 | 2083 | end |
1942 | 2084 |
|
|
0 commit comments