Skip to content

Commit 6e143c0

Browse files
committed
minor fixes & add test
1 parent 9f38cdf commit 6e143c0

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

Parse.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,13 @@
25662566
97DE045A16321492007154E8 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DE045916321492007154E8 /* Security.framework */; };
25672567
97DE045C163214C0007154E8 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DE045B163214C0007154E8 /* SystemConfiguration.framework */; };
25682568
97EB055516F7CCE400E09147 /* PFAnalytics.m in Sources */ = {isa = PBXBuildFile; fileRef = 9739513916B9D28E0010B884 /* PFAnalytics.m */; };
2569+
A6E2958C1E96173D009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2570+
A6E2958D1E96173F009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2571+
A6E2958E1E961741009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2572+
A6E2958F1E961742009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2573+
A6E295901E961744009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2574+
A6E295911E961744009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
2575+
A6E295921E961744009917BF /* ParseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6E295801E961727009917BF /* ParseManagerPrivate.h */; };
25692576
F50C66331B33A708001941A6 /* PFPushUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = F50C66311B33A708001941A6 /* PFPushUtilities.h */; };
25702577
F50C66341B33A708001941A6 /* PFPushUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = F50C66321B33A708001941A6 /* PFPushUtilities.m */; };
25712578
F50C667C1B34B231001941A6 /* PFPushUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = F50C66321B33A708001941A6 /* PFPushUtilities.m */; };
@@ -3470,6 +3477,7 @@
34703477
97DE045B163214C0007154E8 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
34713478
97E18AE41623835600B17A67 /* PFLocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFLocationManager.h; sourceTree = "<group>"; };
34723479
97E18AE51623835600B17A67 /* PFLocationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFLocationManager.m; sourceTree = "<group>"; };
3480+
A6E295801E961727009917BF /* ParseManagerPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParseManagerPrivate.h; sourceTree = "<group>"; };
34733481
E9BBE98E16D18E5800CD7B52 /* PFObject+Subclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "PFObject+Subclass.h"; path = "Parse/PFObject+Subclass.h"; sourceTree = SOURCE_ROOT; };
34743482
E9E81E8316EEF93E001D034F /* PFSubclassing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFSubclassing.h; sourceTree = "<group>"; };
34753483
F50C66311B33A708001941A6 /* PFPushUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFPushUtilities.h; sourceTree = "<group>"; };
@@ -3733,6 +3741,7 @@
37333741
09EEA1351435143500E3A3FA /* ParseInternal.h */,
37343742
81A245F11B1FB188006A6953 /* PFDataProvider.h */,
37353743
812714861AE6F1270076AE8D /* ParseManager.h */,
3744+
A6E295801E961727009917BF /* ParseManagerPrivate.h */,
37363745
812714871AE6F1270076AE8D /* ParseManager.m */,
37373746
8124C8811B27542A00758E00 /* PFCoreDataProvider.h */,
37383747
8196D58B1B0BD23B000465A1 /* PFCoreManager.h */,
@@ -5389,6 +5398,7 @@
53895398
810156481BB3832700D7C7BD /* PFURLSessionDataTaskDelegate.h in Headers */,
53905399
81CA29D21C28DF8F00C4F34A /* PFAnonymousUtils+Deprecated.h in Headers */,
53915400
810156491BB3832700D7C7BD /* PFDateFormatter.h in Headers */,
5401+
A6E295911E961744009917BF /* ParseManagerPrivate.h in Headers */,
53925402
8101564A1BB3832700D7C7BD /* PFCloudCodeController.h in Headers */,
53935403
8101564B1BB3832700D7C7BD /* PFMultiProcessFileLockController.h in Headers */,
53945404
8101564C1BB3832700D7C7BD /* PFCurrentUserController.h in Headers */,
@@ -5549,6 +5559,7 @@
55495559
815F23C51BD04D150054659F /* PFURLSessionCommandRunner.h in Headers */,
55505560
815F23C61BD04D150054659F /* PFRESTObjectCommand.h in Headers */,
55515561
815F23C71BD04D150054659F /* PFCommandRunning.h in Headers */,
5562+
A6E2958F1E961742009917BF /* ParseManagerPrivate.h in Headers */,
55525563
815F23C81BD04D150054659F /* PFRESTCloudCommand.h in Headers */,
55535564
815F23C91BD04D150054659F /* PFProduct.h in Headers */,
55545565
815F23CA1BD04D150054659F /* PFQuery.h in Headers */,
@@ -5654,6 +5665,7 @@
56545665
818AAA7619D36B1C00FC1B3C /* PFFile.h in Headers */,
56555666
816AC9BA1A3F48250031D94C /* PFApplication.h in Headers */,
56565667
F5B0B2EC1B449F1D00F3EBC4 /* BFTask+Private.h in Headers */,
5668+
A6E2958C1E96173D009917BF /* ParseManagerPrivate.h in Headers */,
56575669
F5B0B2ED1B449F1D00F3EBC4 /* PFCategoryLoader.h in Headers */,
56585670
F5B0B2EE1B449F1D00F3EBC4 /* PFThreadsafety.h in Headers */,
56595671
F5B0B2EF1B449F1D00F3EBC4 /* PFRelationState_Private.h in Headers */,
@@ -5997,6 +6009,7 @@
59976009
81C584121C3B0A98000063C6 /* PFFilePersistenceGroup.h in Headers */,
59986010
81C584131C3B0A98000063C6 /* PFRESTQueryCommand.h in Headers */,
59996011
81C584141C3B0A98000063C6 /* PFACLState_Private.h in Headers */,
6012+
A6E2958D1E96173F009917BF /* ParseManagerPrivate.h in Headers */,
60006013
81C584151C3B0A98000063C6 /* PFConfig+Synchronous.h in Headers */,
60016014
81C584161C3B0A98000063C6 /* PFObject.h in Headers */,
60026015
81C584171C3B0A98000063C6 /* PFPushUtilities.h in Headers */,
@@ -6201,6 +6214,7 @@
62016214
81C585701C3B0AA1000063C6 /* PFURLSessionCommandRunner.h in Headers */,
62026215
81C585711C3B0AA1000063C6 /* PFRESTObjectCommand.h in Headers */,
62036216
81C585721C3B0AA1000063C6 /* PFCommandRunning.h in Headers */,
6217+
A6E295901E961744009917BF /* ParseManagerPrivate.h in Headers */,
62046218
81C585731C3B0AA1000063C6 /* PFRESTCloudCommand.h in Headers */,
62056219
81C585741C3B0AA1000063C6 /* PFProduct.h in Headers */,
62066220
81C585751C3B0AA1000063C6 /* PFQuery.h in Headers */,
@@ -6444,6 +6458,7 @@
64446458
81C586EF1C3B0AA9000063C6 /* PFURLSessionDataTaskDelegate.h in Headers */,
64456459
81C586F01C3B0AA9000063C6 /* PFAnonymousUtils+Deprecated.h in Headers */,
64466460
81C586F11C3B0AA9000063C6 /* PFDateFormatter.h in Headers */,
6461+
A6E295921E961744009917BF /* ParseManagerPrivate.h in Headers */,
64476462
81C586F21C3B0AA9000063C6 /* PFCloudCodeController.h in Headers */,
64486463
81C586F31C3B0AA9000063C6 /* PFMultiProcessFileLockController.h in Headers */,
64496464
81C586F41C3B0AA9000063C6 /* PFCurrentUserController.h in Headers */,
@@ -6518,6 +6533,7 @@
65186533
F5B0B3261B44A33100F3EBC4 /* PFAssert.h in Headers */,
65196534
F5B0B3271B44A33100F3EBC4 /* PFAsyncTaskQueue.h in Headers */,
65206535
F5B0B3281B44A33100F3EBC4 /* PFBaseState.h in Headers */,
6536+
A6E2958E1E961741009917BF /* ParseManagerPrivate.h in Headers */,
65216537
F51535091B57240900C49F56 /* PFMutableACLState.h in Headers */,
65226538
F5B0B32B1B44A33100F3EBC4 /* PFCoreDataProvider.h in Headers */,
65236539
814881611B795CD4008763BF /* PFMultiProcessFileLock.h in Headers */,

Parse/Internal/ParseManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "PFUser.h"
2828
#import "PFURLSessionCommandRunner.h"
2929
#import "PFPersistenceController.h"
30+
#import "ParseManagerPrivate.h"
3031

3132
#if !TARGET_OS_WATCH && !TARGET_OS_TV
3233
#import "PFPushManager.h"
@@ -304,6 +305,11 @@ - (PFInstallationIdentifierStore *)installationIdentifierStore {
304305

305306
#pragma mark CommandRunner
306307

308+
// Set Command Runner. Used for testing.
309+
- (void)setCommandRunner:(id<PFCommandRunning>)commandRunner {
310+
_commandRunner = commandRunner;
311+
}
312+
307313
- (id<PFCommandRunning>)commandRunner {
308314
__block id<PFCommandRunning> runner = nil;
309315
dispatch_sync(_commandRunnerAccessQueue, ^{

Parse/Internal/ParseManagerPrivate.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "ParseManager.h"
11+
12+
@interface ParseManager ()
13+
14+
- (void)setCommandRunner:(id<PFCommandRunning>)commandRunner;
15+
16+
@end

Parse/PFInstallation.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "Parse_Private.h"
3030
#import "PFErrorUtilities.h"
3131
#import "PFObjectState_Private.h"
32+
#import "PFObjectConstants.h"
3233

3334
@implementation PFInstallation (Private)
3435

@@ -37,7 +38,8 @@ @implementation PFInstallation (Private)
3738
+ (void)initialize {
3839
static dispatch_once_t onceToken;
3940
dispatch_once(&onceToken, ^{
40-
protectedKeys = PF_SET(PFInstallationKeyDeviceType,
41+
protectedKeys = PF_SET(PFObjectObjectIdRESTKey,
42+
PFInstallationKeyDeviceType,
4143
PFInstallationKeyInstallationId,
4244
PFInstallationKeyTimeZone,
4345
PFInstallationKeyLocaleIdentifier,

Tests/Unit/InstallationUnitTests.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,53 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9+
#import <OCMock/OCMock.h>
910

1011
#import "PFInstallation.h"
1112
#import "PFUnitTestCase.h"
1213
#import "Parse.h"
14+
#import "Parse_Private.h"
15+
#import "PFCommandRunning.h"
16+
#import "ParseManagerPrivate.h"
17+
#import "PFObjectState.h"
18+
#import "PFObjectPrivate.h"
1319

1420
@interface InstallationUnitTests : PFUnitTestCase
1521

1622
@end
1723

1824
@implementation InstallationUnitTests
1925

26+
- (void)testInstallationObjectIdCannotBeChanged {
27+
PFInstallation *installation = [PFInstallation currentInstallation];
28+
PFAssertThrowsInvalidArgumentException(installation.objectId = nil);
29+
PFAssertThrowsInvalidArgumentException(installation[@"objectId"] = @"abc");
30+
}
31+
32+
- (void)testReSaveInstallation {
33+
34+
// enable LDS
35+
[[Parse _currentManager]loadOfflineStoreWithOptions:0];
36+
37+
// create and save installation
38+
PFInstallation *installation = [PFInstallation currentInstallation];
39+
PFObjectState *state = [PFObjectState stateWithParseClassName:[PFInstallation parseClassName] objectId:@"abc" isComplete:YES];
40+
installation._state = state;
41+
[installation save];
42+
43+
// mocking installation was deleted on the server
44+
id commandRunner = PFStrictProtocolMock(@protocol(PFCommandRunning));
45+
[Parse _currentManager].commandRunner = commandRunner;
46+
47+
BFTask *mockedTask = [BFTask taskWithError:[NSError errorWithDomain:@"" code:kPFErrorObjectNotFound userInfo:nil]];
48+
49+
OCMStub([commandRunner runCommandAsync:[OCMArg any] withOptions:PFCommandRunningOptionRetryIfFailed]).andReturn(mockedTask);
50+
51+
installation.deviceToken = @"11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306";
52+
[installation save];
53+
OCMVerifyAll(commandRunner);
54+
}
55+
2056
- (void)testInstallationImmutableFieldsCannotBeChanged {
2157
PFInstallation *installation = [PFInstallation currentInstallation];
2258
installation.deviceToken = @"11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306";

0 commit comments

Comments
 (0)