summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLSendLocationSpec.m
blob: ccd4bafdb409cd0f708dd6676322a038473d24e3 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//
//  SDLSendLocationSpec.m
//  SmartDeviceLink-iOS

#import <Quick/Quick.h>
#import <Nimble/Nimble.h>

#import "SDLNames.h"
#import "SDLSendLocation.h"


QuickSpecBegin(SDLSendLocationSpec)

describe(@"Send Location RPC", ^{
    __block SDLSendLocation *testRequest = nil;
    __block NSNumber *someLongitude = nil;
    __block NSNumber *someLatitude = nil;
    __block NSString *someLocation = nil;
    __block NSString *someLocationDescription = nil;
    __block NSArray *someAddressLines = nil;
    __block NSString *somePhoneNumber = nil;
    __block SDLImage *someImage = nil;
    
    describe(@"when initialized with init", ^{
        beforeEach(^{
            testRequest = [[SDLSendLocation alloc] init];
        });
        
        context(@"when parameters are set correctly", ^{
            beforeEach(^{
                someLongitude = @123.4567;
                someLatitude = @65.4321;
                someLocation = @"Livio";
                someLocationDescription = @"A great place to work";
                someAddressLines = @[@"3136 Hilton Rd", @"Ferndale, MI", @"48220"];
                somePhoneNumber = @"248-591-0333";
                someImage = [[SDLImage alloc] init];
                
                testRequest.longitudeDegrees = someLongitude;
                testRequest.latitudeDegrees = someLatitude;
                testRequest.locationName = someLocation;
                testRequest.locationDescription = someLocationDescription;
                testRequest.addressLines = someAddressLines;
                testRequest.phoneNumber = somePhoneNumber;
                testRequest.locationImage = someImage;
            });
            
            // Since all the properties are immutable, a copy should be executed as a retain, which means they should be identical
            it(@"should get longitude correctly", ^{
                expect(testRequest.longitudeDegrees).to(equal(someLongitude));
                expect(testRequest.longitudeDegrees).to(beIdenticalTo(someLongitude));
            });
            
            it(@"should get latitude correctly", ^{
                expect(testRequest.latitudeDegrees).to(equal(someLatitude));
                expect(testRequest.latitudeDegrees).to(beIdenticalTo(someLatitude));
            });
            
            it(@"should get location correctly", ^{
                expect(testRequest.locationName).to(equal(someLocation));
                expect(testRequest.locationName).to(beIdenticalTo(someLocation));
            });
            
            it(@"should get location description correctly", ^{
                expect(testRequest.locationDescription).to(equal(someLocationDescription));
                expect(testRequest.locationDescription).to(beIdenticalTo(someLocationDescription));
            });
            
            it(@"should get address lines correctly", ^{
                expect(testRequest.addressLines).to(equal(someAddressLines));
                expect(testRequest.addressLines).to(beIdenticalTo(someAddressLines));
            });
            
            it(@"should get phone number correctly", ^{
                expect(testRequest.phoneNumber).to(equal(somePhoneNumber));
                expect(testRequest.phoneNumber).to(beIdenticalTo(somePhoneNumber));
            });
            
            it(@"should get image correctly", ^{
                expect(testRequest.locationImage).to(equal(someImage));
                expect(testRequest.locationImage).to(beIdenticalTo(someImage));
            });
        });
        
        context(@"when parameters are not set", ^{
            it(@"should return nil for longitude", ^{
                expect(testRequest.longitudeDegrees).to(beNil());
            });
            
            it(@"should return nil for latitude", ^{
                expect(testRequest.latitudeDegrees).to(beNil());
            });
            
            it(@"should return nil for location", ^{
                expect(testRequest.locationName).to(beNil());
            });
            
            it(@"should return nil for location description", ^{
                expect(testRequest.locationDescription).to(beNil());
            });
            
            it(@"should return nil for address lines", ^{
                expect(testRequest.addressLines).to(beNil());
            });
            
            it(@"should return nil for phone number", ^{
                expect(testRequest.phoneNumber).to(beNil());
            });
            
            it(@"should return nil for image", ^{
                expect(testRequest.locationImage).to(beNil());
            });
        });
    });
    
    describe(@"when initialized with a dictionary", ^{
        context(@"when parameters are set correctly", ^{
            beforeEach(^{
                someLongitude = @123.4567;
                someLatitude = @65.4321;
                someLocation = @"Livio";
                someLocationDescription = @"A great place to work";
                someAddressLines = @[@"3136 Hilton Rd", @"Ferndale, MI", @"48220"];
                somePhoneNumber = @"248-591-0333";
                someImage = [[SDLImage alloc] init];
                NSDictionary *initDict = @{
                                           NAMES_request: @{
                                                   NAMES_parameters: @{
                                                           NAMES_longitudeDegrees: someLongitude,
                                                           NAMES_latitudeDegrees: someLatitude,
                                                           NAMES_locationName: someLocation,
                                                           NAMES_locationDescription: someLocationDescription,
                                                           NAMES_addressLines: someAddressLines,
                                                           NAMES_phoneNumber: somePhoneNumber,
                                                           NAMES_locationImage: someImage
                                                           }
                                                   }
                                           };
                
                testRequest = [[SDLSendLocation alloc] initWithDictionary:[NSMutableDictionary dictionaryWithDictionary:initDict]];
            });
            
            // Since all the properties are immutable, a copy should be executed as a retain, which means they should be identical
            it(@"should get longitude correctly", ^{
                expect(testRequest.longitudeDegrees).to(equal(someLongitude));
                expect(testRequest.longitudeDegrees).to(beIdenticalTo(someLongitude));
            });
            
            it(@"should get latitude correctly", ^{
                expect(testRequest.latitudeDegrees).to(equal(someLatitude));
                expect(testRequest.latitudeDegrees).to(beIdenticalTo(someLatitude));
            });
            
            it(@"should get location correctly", ^{
                expect(testRequest.locationName).to(equal(someLocation));
                expect(testRequest.locationName).to(beIdenticalTo(someLocation));
            });
            
            it(@"should get location description correctly", ^{
                expect(testRequest.locationDescription).to(equal(someLocationDescription));
                expect(testRequest.locationDescription).to(beIdenticalTo(someLocationDescription));
            });
            
            it(@"should get address lines correctly", ^{
                expect(testRequest.addressLines).to(equal(someAddressLines));
                expect(testRequest.addressLines).to(beIdenticalTo(someAddressLines));
            });
            
            it(@"should get phone number correctly", ^{
                expect(testRequest.phoneNumber).to(equal(somePhoneNumber));
                expect(testRequest.phoneNumber).to(beIdenticalTo(somePhoneNumber));
            });
            
            it(@"should get image correctly", ^{
                expect(testRequest.locationImage).to(equal(someImage));
                expect(testRequest.locationImage).to(beIdenticalTo(someImage));
            });
        });
    
        context(@"when parameters are not set", ^{
            beforeEach(^{
                NSDictionary *initDict = @{
                                           NAMES_request: @{
                                                   NAMES_parameters: @{}
                                                   }
                                           };
                
                testRequest = [[SDLSendLocation alloc] initWithDictionary:[NSMutableDictionary dictionaryWithDictionary:initDict]];
            });
            
            it(@"should return nil for longitude", ^{
                expect(testRequest.longitudeDegrees).to(beNil());
            });
            
            it(@"should return nil for latitude", ^{
                expect(testRequest.latitudeDegrees).to(beNil());
            });
            
            it(@"should return nil for location", ^{
                expect(testRequest.locationName).to(beNil());
            });
            
            it(@"should return nil for location description", ^{
                expect(testRequest.locationDescription).to(beNil());
            });
            
            it(@"should return nil for address lines", ^{
                expect(testRequest.addressLines).to(beNil());
            });
            
            it(@"should return nil for phone number", ^{
                expect(testRequest.phoneNumber).to(beNil());
            });
            
            it(@"should return nil for image", ^{
                expect(testRequest.locationImage).to(beNil());
            });
        });
    });
});

QuickSpecEnd