Digits Sandbox

Digits wants to simplify your testing by providing the Digits Sandbox.

Developers can use the Digits Sandbox to test Authentication and “Find your Friends” without a network connection and mock both success and error states. Now you can add Digits tests on CI or test your Digits flows as often as you want without triggering rate limits, requiring a legitimate test phone number, creating test contacts, or requiring a manual code entry step.

Getting Started

The Sandbox works by immediately triggering your completion callback with a success or error result.

This is done by setting the debugOverrides property on the Digits singleton:

// Objective-C
Digits *digits = [Digits sharedInstance];
DGTSession *session = [DGTDebugConfiguration defaultDebugSession];
digits.debugOverrides = [[DGTDebugConfiguration alloc] initSuccessStateWithDigitsSession:session];
// Swift
let digits = Digits.sharedInstance()
let session = DGTDebugConfiguration.defaultDebugSession()
digits.debugOverrides = DGTDebugConfiguration(successStateWithDigitsSession: session)

Alternatively, override the Digits flow to return any valid DGTErrorCode:

// Objective-C
Digits *digits = [Digits sharedInstance];
digits.debugOverrides = [[DGTDebugConfiguration alloc] initErrorStateWithDigitsError:DGTErrorCodeUnableToConfirmNumber];
// Swift
let digits = Digits.sharedInstance()
digits.debugOverrides = DGTDebugConfiguration(errorStateWithDigitsError: .UnableToConfirmNumber)

Override contacts upload and lookup behavior as well:

// Objective-C
DGTContacts *digitsContacts = [DGTContacts alloc] initWithUserSession:yourSession];

// Convenience helper to generate user objects
NSArray *stubbedUsers = [DGTContactsDebugConfiguration stubbedContactsWithDigitsUserIDs:@[@"1", @"2", @"3"]];

DGTContactsDebugConfiguration *overrides = [[DGTContactsDebugConfiguration alloc] initSuccessStateWithContacts:stubbedUsers];

// Provide debug overrides for upload and / or lookup flows
digitsContacts.uploadDebugOverrides = overrides;
digitsContacts.lookupDebugOverrides = overrides;
// Swift
let digitsContacts = DGTContacts(userSession: yourSession)

// Convenience helper to generate user objects
let stubbedUsers = DGTContactsDebugConfiguration.stubbedContactsWithDigitsUserIDs(["1", "2", "3"])

// Provide debug overrides for upload and / or lookup flows
digitsContacts.uploadDebugOverrides = DGTContactsDebugConfiguration(successStateWithContacts: stubbedUsers)
digitsContacts.lookupDebugOverrides = DGTContactsDebugConfiguration(successStateWithContacts: stubbedUsers)

In Digits’ Authentication, we return a dummy user’s auth token. Note: This token is not a valid token, and any requests to the Digits service using this token will fail.

For the “Find your Friends” workflow, the sandbox will bypass uploading your contacts to the service. When you lookup matches, the Sandbox returns two matching friend ids. Note: These ids are not valid user ids, and should not be preserved as legitimate contacts outside of development.