-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datamob sdk methods #177
Merged
Merged
Datamob sdk methods #177
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b10123b
WEB-2112 Datamob sdk methods
atabel ae0ecec
video demo
atabel f64eab0
fix docs
atabel ff495b4
invalidPassword -> invalidPhoneNumber
atabel 6765be8
added errorMessage
atabel 41faec9
change app version to 25.x
atabel 8b2cbfd
registerDatamobUser error case
atabel da8f8ce
Merge branch 'master' into atoledano-datamob
atabel 4c6e24d
export methods
atabel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
registerDatamobUser, | ||
requestDatamobDeviceAdmin, | ||
validateDatamobRequirements, | ||
} from '../datamob'; | ||
import {createFakeAndroidPostMessage} from './fake-post-message'; | ||
|
||
test('requestDatamobDeviceAdmin', async () => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('REQUEST_DATAMOB_DEVICE_ADMIN'); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'REQUEST_DATAMOB_DEVICE_ADMIN', | ||
id: msg.id, | ||
payload: { | ||
isAdmin: true, | ||
}, | ||
}), | ||
}); | ||
|
||
const res = await requestDatamobDeviceAdmin(); | ||
expect(res).toEqual({isAdmin: true}); | ||
}); | ||
|
||
test('registerDatamobUser', async () => { | ||
const phoneNumber = '666112233'; | ||
const tokenPassword = 'sometoken'; | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('REGISTER_DATAMOB_USER'); | ||
expect(msg.payload).toEqual({phoneNumber, tokenPassword}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'REGISTER_DATAMOB_USER', | ||
id: msg.id, | ||
}), | ||
}); | ||
|
||
const res = await registerDatamobUser({phoneNumber, tokenPassword}); | ||
expect(res).toBeUndefined(); | ||
}); | ||
|
||
test('registerDatamobUser error', async () => { | ||
const phoneNumber = '666112233'; | ||
const tokenPassword = 'sometoken'; | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('REGISTER_DATAMOB_USER'); | ||
expect(msg.payload).toEqual({phoneNumber, tokenPassword}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'ERROR', | ||
id: msg.id, | ||
payload: { | ||
code: 500, | ||
reason: 'Registration error', | ||
}, | ||
}), | ||
}); | ||
|
||
await expect( | ||
registerDatamobUser({phoneNumber, tokenPassword}), | ||
).rejects.toEqual({ | ||
code: 500, | ||
reason: 'Registration error', | ||
}); | ||
}); | ||
|
||
test('validateDatamobRequirements', async () => { | ||
const phoneNumber = '666112233'; | ||
const tokenPassword = 'sometoken'; | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('VALIDATE_DATAMOB_REQUIREMENTS'); | ||
expect(msg.payload).toEqual({phoneNumber, tokenPassword}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'VALIDATE_DATAMOB_REQUIREMENTS', | ||
id: msg.id, | ||
payload: { | ||
requirements: { | ||
deviceAdmin: true, | ||
googleAccount: true, | ||
lockPassword: true, | ||
accessibilityOption: true, | ||
invalidPhoneNumber: true, | ||
invalidToken: true, | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
const res = await validateDatamobRequirements({phoneNumber, tokenPassword}); | ||
|
||
expect(res).toEqual({ | ||
requirements: { | ||
deviceAdmin: true, | ||
googleAccount: true, | ||
lockPassword: true, | ||
accessibilityOption: true, | ||
invalidPhoneNumber: true, | ||
invalidToken: true, | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {postMessageToNativeApp} from './post-message'; | ||
|
||
export const requestDatamobDeviceAdmin = (): Promise<{isAdmin: boolean}> => | ||
postMessageToNativeApp({ | ||
type: 'REQUEST_DATAMOB_DEVICE_ADMIN', | ||
payload: {}, | ||
}).then(({isAdmin}) => ({isAdmin})); | ||
|
||
export const registerDatamobUser = ({ | ||
phoneNumber, | ||
tokenPassword, | ||
}: { | ||
phoneNumber: string; | ||
tokenPassword: string; | ||
}): Promise<void> => | ||
postMessageToNativeApp({ | ||
type: 'REGISTER_DATAMOB_USER', | ||
payload: {phoneNumber, tokenPassword}, | ||
}); | ||
|
||
export const validateDatamobRequirements = ({ | ||
phoneNumber, | ||
tokenPassword, | ||
}: { | ||
phoneNumber: string; | ||
tokenPassword: string; | ||
}): Promise<{ | ||
requirements: { | ||
deviceAdmin: boolean; | ||
googleAccount: boolean; | ||
lockPassword: boolean; | ||
accessibilityOption: boolean; | ||
invalidPhoneNumber: boolean; | ||
invalidToken: boolean; | ||
}; | ||
}> => | ||
postMessageToNativeApp({ | ||
type: 'VALIDATE_DATAMOB_REQUIREMENTS', | ||
payload: {phoneNumber, tokenPassword}, | ||
}).then(({requirements}) => ({requirements})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated. Just update missing doc