/
infogram-ruby_spec.rb
63 lines (55 loc) · 1.86 KB
/
infogram-ruby_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'helper'
describe 'Infogram' do
let (:api_key) { 'nMECGhmHe9' }
let (:api_secret) { 'da5xoLrCCx' }
let (:client) { infogram_client(api_key, api_secret) }
let (:params) { {
content: [
{
type: 'h1',
text: 'Hello infogr.am'
}
],
theme_id: 45,
publish: false,
title: 'Hello'
}
}
context 'Signature' do
let (:encoded_params) { 'api_key=nMECGhmHe9&content=%5B%7B%22type%22%3A%22h1%22%2C%22text%22%3A%22Hello%20infogr.am%22%7D%5D&publish=false&theme_id=45&title=Hello' }
it 'should encode params' do
params[:api_key] = api_key
expect(client.decode_params(params)).to eq(encoded_params)
end
it 'should generate signature' do
params[:api_key] = api_key
signature = client.signature('post', 'infographics', params)
expect(signature).to eq('bqwCqAk1TWDYNy3eqV0BiNuIERQ=')
end
end
context 'Themes' do
it 'should return themes list' do
stub_get('themes').to_return(with_fixture('themes.json'))
themes = client.get_themes()
expect(themes[0]['id']).to eq(61)
expect(themes[1]['title']).to eq('Megaphone')
end
end
context 'Infographic' do
it 'GET infographics' do
stub_get('infographics').to_return(with_fixture('infographics.json'))
ig = client.get_infographics
expect(ig[1]['id']).to eq('d819d9b7-67fb-40ec-9400-d63cc209aea8')
end
it 'GET infographics/:id' do
stub_get('infographics').to_return(with_fixture('infographic.json'))
ig = client.get_infographic('d819d9b7-67fb-40ec-9400-d63cc209aea8')
expect(ig['title']).to eq('sample infographic 2')
end
it 'POST infographics' do
stub_post('infographics').to_return(with_fixture('infographic.json'))
ig = client.create_infographic(params)
expect(ig['title']).to eq('sample infographic 2')
end
end
end