-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
257 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
'API_URL': 'api.early-birds.fr' | ||
} |
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 |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { isEqual, Encode } from '../utils/Utils' | ||
|
||
export const ebProfileExist = isEqual | ||
|
||
export const cookieIsValid = (cookie, duration) => { | ||
if (!cookie) return false | ||
if (!cookie.lastIdentify) return false | ||
console.log('hello') | ||
return new Date().getTime() - cookie.lastIdentify < duration | ||
// last identify is greater than duration | ||
export const cookieDurationIsOutdated = (cookie, duration) => { | ||
if (!cookie) return true; | ||
if (cookie && cookie.lastIdentify == undefined) return true; | ||
return (new Date().getTime() - cookie.lastIdentify) > duration | ||
} | ||
|
||
export const profileHasChanged = | ||
(cookie, profile) => | ||
!isEqual(cookie.hash, Encode(profile)) | ||
// the given cookie hash is different from the given profile | ||
export const cookieHashAndProfileMatch = | ||
(cookie, profile) => | ||
isEqual(cookie.hash, Encode(profile)) | ||
|
||
export const shouldInitiateIdentifyRequest = (cookie, profile, duration) => { | ||
if (!cookie) | ||
return true | ||
if (!cookieHashAndProfileMatch(cookie, profile)) | ||
return true | ||
if (duration && cookieDurationIsOutdated(cookie, duration)) | ||
return true | ||
return false | ||
} |
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 |
---|---|---|
@@ -1,45 +1,46 @@ | ||
import { | ||
ebProfileExist, | ||
cookieIsValid, | ||
profileHasChanged } from '../../src/modules/profileValidationCheck' | ||
cookieDurationIsOutdated, | ||
cookieHashAndProfileMatch, | ||
shouldInitiateIdentifyRequest } from '../../src/modules/profileValidationCheck' | ||
import { Encode } from '../../src/utils/Utils' | ||
|
||
const defaultProfile = { | ||
hash: null, | ||
lastIdentify: null, | ||
hash: null, | ||
lastIdentify: null, | ||
} | ||
|
||
describe('profileValidationCheck', () => { | ||
describe('ebProfileExist', () => { | ||
describe('ebCookieMatchProfile', () => { | ||
|
||
it('should be truthy when cookie and defaultProfile are the same', () => { | ||
expect(ebProfileExist(defaultProfile, defaultProfile)).toBeTruthy() | ||
}) | ||
it('should be falsy when cookie and defaultProfile are different', () => { | ||
expect(ebProfileExist({}, defaultProfile)).toBeFalsy() | ||
}) | ||
it('should be truthy if cookie hash and defaultProfile are the same', () => { | ||
expect(cookieHashAndProfileMatch({ hash: Encode(defaultProfile) }, defaultProfile)).toBeTruthy() | ||
}) | ||
it('should be falsy if cookie hash and defaultProfile are different', () => { | ||
expect(cookieHashAndProfileMatch({ hash: 'hash' }, defaultProfile)).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('cookieIsValid', () => { | ||
describe('cookieDurationIsOutdated', () => { | ||
|
||
it('should be falsy if cookie does not exist', () => { | ||
expect(cookieIsValid(null)).toBeFalsy() | ||
}) | ||
it('should be falsy if cookie.lastIdentify does not exist', () => { | ||
expect(cookieIsValid({})).toBeFalsy() | ||
}) | ||
it('should be falsy if lastIdentify > duration', () => { | ||
Date.prototype.getTime = () => 5 | ||
const cookie = { | ||
lastIdentify: 0 | ||
} | ||
expect(cookieIsValid(cookie, 2)).toBeFalsy() | ||
}) | ||
it('should be truthy if lastIdentify < duration', () => { | ||
Date.prototype.getTime = () => 0 | ||
const cookie = { | ||
lastIdentify: 0 | ||
} | ||
expect(cookieIsValid(cookie, 2)).toBeTruthy() | ||
}) | ||
it('should be truthy if cookie does not exist', () => { | ||
expect(cookieDurationIsOutdated(null)).toBeTruthy() | ||
}) | ||
it('should be truthy if cookie.lastIdentify does not exist', () => { | ||
expect(cookieDurationIsOutdated({})).toBeTruthy() | ||
}) | ||
it('should be truthy if lastIdentify > duration', () => { | ||
Date.prototype.getTime = () => 5 | ||
const cookie = { | ||
lastIdentify: 0 | ||
} | ||
expect(cookieDurationIsOutdated(cookie, 2)).toBeTruthy() | ||
}) | ||
it('should be falsy if lastIdentify < duration', () => { | ||
Date.prototype.getTime = () => 0 | ||
const cookie = { | ||
lastIdentify: 0 | ||
} | ||
expect(cookieDurationIsOutdated(cookie, 2)).toBeFalsy() | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.