|
2 | 2 |
|
3 | 3 | describe XClarityClient do |
4 | 4 | before :all do |
5 | | - WebMock.allow_net_connect! # -- This line should be uncommented if you're using external mock test |
| 5 | + # -- The next line should be uncommented |
| 6 | + # if you're using external mock test |
| 7 | + WebMock.allow_net_connect! |
6 | 8 |
|
7 | 9 | conf = XClarityClient::Configuration.new( |
8 | 10 | username: ENV['LXCA_USERNAME'], |
|
13 | 15 | ) |
14 | 16 |
|
15 | 17 | @client = XClarityClient::Client.new(conf) |
| 18 | + @host = ENV['LXCA_HOST'] |
16 | 19 |
|
17 | | - @includeAttributes = %w(accessState activationKeys) |
18 | | - @excludeAttributes = %w(accessState activationKeys) |
| 20 | + @include_attributes = %w(access_state activation_keys) |
| 21 | + @exclude_attributes = %w(access_state activation_keys) |
19 | 22 | end |
20 | 23 |
|
21 | 24 | before :each do |
22 | | - @uuidArray = @client.discover_nodes.map { |node| node.uuid } |
| 25 | + @uuid_array = @client.discover_nodes.map(&:uuid) |
23 | 26 | end |
24 | 27 |
|
25 | 28 | it 'has a version number' do |
26 | 29 | expect(XClarityClient::VERSION).not_to be nil |
27 | 30 | end |
28 | 31 |
|
29 | 32 | describe 'GET /nodes' do |
30 | | - |
31 | 33 | it 'should respond with an array' do |
32 | 34 | expect(@client.discover_nodes.class).to eq(Array) |
33 | 35 | end |
34 | | - |
35 | 36 | end |
36 | 37 |
|
37 | 38 | describe 'GET /nodes/UUID' do |
38 | 39 | context 'with include attributes' do |
39 | 40 | it 'required attributes should not be nil' do |
40 | | - response = @client.fetch_nodes(@uuidArray, @includeAttributes,nil) |
| 41 | + response = @client.fetch_nodes(@uuid_array, @include_attributes, nil) |
41 | 42 | response.map do |node| |
42 | | - @includeAttributes.map do |attribute| |
| 43 | + @include_attributes.map do |attribute| |
43 | 44 | expect(node.send(attribute)).not_to be_nil |
44 | 45 | end |
45 | 46 | end |
|
48 | 49 |
|
49 | 50 | context 'with excludeAttributes' do |
50 | 51 | it 'excluded attributes should to be nil' do |
51 | | - response = @client.fetch_nodes(@uuidArray, nil, @excludeAttributes) |
| 52 | + response = @client.fetch_nodes(@uuid_array, nil, @exclude_attributes) |
52 | 53 | response.map do |node| |
53 | | - @excludeAttributes.map do |attribute| |
| 54 | + @exclude_attributes.map do |attribute| |
54 | 55 | expect(node.send(attribute)).to be_nil |
55 | 56 | end |
56 | 57 | end |
|
59 | 60 | end |
60 | 61 |
|
61 | 62 | describe 'GET /nodes/UUID,UUID,...,UUID' do |
62 | | - |
63 | 63 | context 'with includeAttributes' do |
64 | 64 | it 'required attributes shoud not be nil ' do |
65 | | - response = @client.fetch_nodes(@uuidArray, @includeAttributes,nil) |
| 65 | + response = @client.fetch_nodes(@uuid_array, @include_attributes, nil) |
66 | 66 | response.map do |node| |
67 | | - @includeAttributes.map do |attribute| |
| 67 | + @include_attributes.map do |attribute| |
68 | 68 | expect(node.send(attribute)).not_to be_nil |
69 | 69 | end |
70 | 70 | end |
|
73 | 73 |
|
74 | 74 | context 'with excludeAttributes' do |
75 | 75 | it 'excluded attributes shoud to be nil' do |
76 | | - response = @client.fetch_nodes(@uuidArray, nil, @excludeAttributes) |
| 76 | + response = @client.fetch_nodes(@uuid_array, nil, @exclude_attributes) |
77 | 77 | response.map do |node| |
78 | | - @excludeAttributes.map do |attribute| |
| 78 | + @exclude_attributes.map do |attribute| |
79 | 79 | expect(node.send(attribute)).to be_nil |
80 | 80 | end |
81 | 81 | end |
|
84 | 84 | end |
85 | 85 |
|
86 | 86 | describe 'GET /nodes' do |
87 | | - |
88 | 87 | context 'with includeAttributes' do |
89 | 88 | it 'required attributes should not be nil' do |
90 | | - response = @client.fetch_nodes(nil,@includeAttributes,nil) |
| 89 | + response = @client.fetch_nodes(nil, @include_attributes, nil) |
91 | 90 | response.first do |node| |
92 | | - @includeAttributes.map do |attribute| |
| 91 | + @include_attributes.map do |attribute| |
93 | 92 | expect(node.send(attribute)).not_to be_nil |
94 | 93 | end |
95 | 94 | end |
|
98 | 97 |
|
99 | 98 | context 'with excludeAttributes' do |
100 | 99 | it 'excluded attributes should be nil' do |
101 | | - response = @client.fetch_nodes(nil,nil,@excludeAttributes) |
| 100 | + response = @client.fetch_nodes(nil, nil, @exclude_attributes) |
102 | 101 | response.map do |node| |
103 | | - @excludeAttributes.map do |attribute| |
| 102 | + @exclude_attributes.map do |attribute| |
104 | 103 | expect(node.send(attribute)).to be_nil |
105 | 104 | end |
106 | 105 | end |
|
110 | 109 |
|
111 | 110 | describe 'Get /node' do |
112 | 111 | it 'should power down system' do |
113 | | - response = @client.power_off_node(@uuidArray[0]) |
| 112 | + response = @client.power_off_node(@uuid_array[0]) |
114 | 113 | expect(response.status).to eq(200) |
115 | | - |
116 | 114 | end |
117 | 115 | end |
118 | 116 |
|
119 | 117 | describe 'PUT /nodes/UUID' do |
120 | 118 | context 'with a leds object' do |
121 | 119 | context 'with state == "On" and name == "Identify"' do |
122 | 120 | it 'turns on the location led' do |
123 | | - @client.turn_on_loc_led(@uuidArray[0]) |
124 | | - uri = "http://example.com/nodes/#{@uuidArray[0]}" |
| 121 | + @client.turn_on_loc_led(@uuid_array[0]) |
| 122 | + uri = "#{@host}/nodes/#{@uuid_array[0]}" |
125 | 123 | request_body = { 'body' => { 'leds' => [{ 'name' => 'Identify', |
126 | 124 | 'state' => 'On' }] } } |
127 | 125 | expect(a_request(:put, uri).with(request_body)).to have_been_made |
128 | 126 | end |
129 | 127 | end |
130 | | - |
131 | 128 | context 'with state == "Off" and name == "Identify"' do |
132 | 129 | it 'turns off the location led' do |
133 | | - @client.turn_off_loc_led(@uuidArray[0]) |
134 | | - uri = "http://example.com/nodes/#{@uuidArray[0]}" |
| 130 | + @client.turn_off_loc_led(@uuid_array[0]) |
| 131 | + uri = "#{@host}/nodes/#{@uuid_array[0]}" |
135 | 132 | request_body = { 'body' => { 'leds' => [{ 'name' => 'Identify', |
136 | 133 | 'state' => 'Off' }] } } |
137 | 134 | expect(a_request(:put, uri).with(request_body)).to have_been_made |
138 | 135 | end |
139 | 136 | end |
140 | | - |
141 | 137 | context 'with state == "Blinking" and name == "Identify"' do |
142 | 138 | it 'turns on the blinking location led' do |
143 | | - @client.blink_loc_led(@uuidArray[0]) |
144 | | - uri = "http://example.com/nodes/#{@uuidArray[0]}" |
| 139 | + @client.blink_loc_led(@uuid_array[0]) |
| 140 | + uri = "#{@host}/nodes/#{@uuid_array[0]}" |
145 | 141 | request_body = { 'body' => { 'leds' => [{ 'name' => 'Identify', |
146 | 142 | 'state' => 'Blinking' }] } } |
147 | 143 | expect(a_request(:put, uri).with(request_body)).to have_been_made |
|
0 commit comments