-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supporting device token type using integrations object
- Loading branch information
1 parent
02f8dbd
commit 319a193
Showing
6 changed files
with
444 additions
and
4 deletions.
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
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,87 @@ | ||
const { deduceTokenType } = require('./utils'); | ||
|
||
describe('deduceTokenType', () => { | ||
// deduces token type from integration object when valid token type is present | ||
it('should return the token type from integration object when it is valid', () => { | ||
const message = { | ||
integrations: { | ||
clevertap: { | ||
deviceTokenType: 'fcm', | ||
}, | ||
}, | ||
}; | ||
const deviceOS = 'android'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toBe('fcm'); | ||
}); | ||
|
||
// handles null or undefined message input gracefully | ||
it('should return default token type based on deviceOS when message is null', () => { | ||
const message = null; | ||
const deviceOS = 'android'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toBe('fcm'); | ||
}); | ||
|
||
// returns 'fcm' when deviceOS is 'android' and no valid token type is present | ||
it("should return 'fcm' when deviceOS is 'android' and no valid token type is present", () => { | ||
const message = { integrations: { clevertap: { deviceTokenType: null } } }; | ||
const result = deduceTokenType(message, 'android'); | ||
expect(result).toBe('fcm'); | ||
}); | ||
|
||
// returns 'apns' when deviceOS is not 'android' and no valid token type is present | ||
it("should return 'apns' when deviceOS is not 'android' and no valid token type is present", () => { | ||
const message = { integrations: { clevertap: { deviceTokenType: null } } }; | ||
const result = deduceTokenType(message, 'ios'); | ||
expect(result).toBe('apns'); | ||
}); | ||
|
||
// handles null or undefined deviceOS input gracefully | ||
it('should return default token type when deviceOS is null', () => { | ||
const message = {}; | ||
const deviceOS = null; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toEqual('apns'); | ||
}); | ||
|
||
// handles empty integration object in message | ||
it('should return default token type when integration object is empty', () => { | ||
const message = { integrations: {} }; | ||
const deviceOS = 'ios'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toEqual('apns'); | ||
}); | ||
|
||
// handles integration object with invalid token type | ||
it('should return default token type when integration object has an invalid token type', () => { | ||
const message = { integrations: { clevertap: { deviceTokenType: 'invalidType' } } }; | ||
const deviceOS = 'ios'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toEqual('apns'); | ||
}); | ||
|
||
// handles integration object with no token type | ||
it('should return default token type when integration object has no token type', () => { | ||
const message = { integrations: { clevertap: {} } }; | ||
const deviceOS = 'android'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toEqual('fcm'); | ||
}); | ||
|
||
// verifies integration object retrieval with 'clevertap' as destination name | ||
it('should retrieve correct device token type for CleverTap destination', () => { | ||
const message = { integrations: { clevertap: { deviceTokenType: 'fcm' } } }; | ||
const deviceOS = 'ios'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toBe('fcm'); | ||
}); | ||
|
||
// checks for case sensitivity in deviceOS values | ||
it('should handle case sensitivity in deviceOS values', () => { | ||
const message = { integrations: { clevertap: { deviceTokenType: 'fcm' } } }; | ||
const deviceOS = 'Android'; | ||
const result = deduceTokenType(message, deviceOS); | ||
expect(result).toBe('fcm'); | ||
}); | ||
}); |
Oops, something went wrong.