-
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
feat(qualtrics methods): displayQualtricsIntercept, setQualtricsProperties, isQualtricsInterceptAvailableForUser #185
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
displayQualtricsIntercept, | ||
isQualtricsInterceptAvailableForUser, | ||
setQualtricsProperties, | ||
} from '../qualtrics'; | ||
import {createFakeAndroidPostMessage} from './fake-post-message'; | ||
|
||
test('displayQualtricsIntercept', async () => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('DISPLAY_QUALTRICS_INTERCEPT'); | ||
expect(msg.payload).toEqual({interceptId: 'anyInterceptId'}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'DISPLAY_QUALTRICS_INTERCEPT', | ||
id: msg.id, | ||
payload: { | ||
displayed: true, | ||
}, | ||
}), | ||
}); | ||
|
||
const res = await displayQualtricsIntercept({ | ||
interceptId: 'anyInterceptId', | ||
}); | ||
expect(res).toEqual({displayed: true}); | ||
}); | ||
|
||
test('setQualtricsProperties', async () => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('SET_QUALTRICS_PROPERTIES'); | ||
expect(msg.payload).toEqual({ | ||
stringProperties: [{key: 'stringKey', value: 'stringValue'}], | ||
numberProperties: [{key: 'numberKey', value: 42}], | ||
dateTimePropertyKeys: ['dateTimeKey'], | ||
}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'SET_QUALTRICS_PROPERTIES', | ||
id: msg.id, | ||
}), | ||
}); | ||
|
||
const res = await setQualtricsProperties({ | ||
stringProperties: [{key: 'stringKey', value: 'stringValue'}], | ||
numberProperties: [{key: 'numberKey', value: 42}], | ||
dateTimePropertyKeys: ['dateTimeKey'], | ||
}); | ||
|
||
expect(res).toBeUndefined(); | ||
}); | ||
|
||
test('isQualtricsInterceptAvailableForUser', async () => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('IS_QUALTRICS_INTERCEPT_AVAILABLE_FOR_USER'); | ||
expect(msg.payload).toEqual({interceptId: 'anyInterceptId'}); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'IS_QUALTRICS_INTERCEPT_AVAILABLE_FOR_USER', | ||
id: msg.id, | ||
payload: { | ||
isAvailable: true, | ||
}, | ||
}), | ||
}); | ||
|
||
const res = await isQualtricsInterceptAvailableForUser({ | ||
interceptId: 'anyInterceptId', | ||
}); | ||
expect(res).toEqual({isAvailable: true}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {postMessageToNativeApp} from './post-message'; | ||
|
||
export const displayQualtricsIntercept = ({ | ||
interceptId, | ||
}: { | ||
interceptId: string; | ||
}): Promise<{displayed: true}> => | ||
postMessageToNativeApp({ | ||
type: 'DISPLAY_QUALTRICS_INTERCEPT', | ||
payload: {interceptId}, | ||
}); | ||
|
||
type QualtricsProperty<T> = { | ||
key: string; | ||
value: T; | ||
}; | ||
|
||
export const setQualtricsProperties = ({ | ||
stringProperties, | ||
numberProperties, | ||
dateTimePropertyKeys, | ||
}: { | ||
stringProperties: Array<QualtricsProperty<string>>; | ||
numberProperties: Array<QualtricsProperty<number>>; | ||
dateTimePropertyKeys: Array<string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we didn't specified that in the spec, but probably is interesting to give these properties a default value (empty array) from js side? WDYT @dhidalgofadrique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm, done |
||
}): Promise<void> => | ||
postMessageToNativeApp({ | ||
type: 'SET_QUALTRICS_PROPERTIES', | ||
payload: {stringProperties, numberProperties, dateTimePropertyKeys}, | ||
}); | ||
|
||
export const isQualtricsInterceptAvailableForUser = ({ | ||
interceptId, | ||
}: { | ||
interceptId: string; | ||
}): Promise<{isAvailable: boolean}> => | ||
postMessageToNativeApp({ | ||
type: 'IS_QUALTRICS_INTERCEPT_AVAILABLE_FOR_USER', | ||
payload: {interceptId}, | ||
}); |
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.
All methods will be available only for iOS by the moment. In android it's expected to be integrated at some next version.
We can add a "Only for iOS" comment, and when it is integrated in android we can update the doc with the proper version.