-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: splited header interpreter tests into multiple files
- Loading branch information
1 parent
85336da
commit 4f938a4
Showing
4 changed files
with
108 additions
and
85 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,33 @@ | ||
import { defaultHeaderInterpreter } from '../../src/header/interpreter'; | ||
import { Header } from '../../src/util/headers'; | ||
|
||
describe('test Cache-Control header', () => { | ||
it('tests with cache preventing headers', () => { | ||
const noStore = defaultHeaderInterpreter({ | ||
[Header.CacheControl]: 'no-store' | ||
}); | ||
|
||
expect(noStore).toBe('dont cache'); | ||
|
||
const noCache = defaultHeaderInterpreter({ | ||
[Header.CacheControl]: 'no-cache' | ||
}); | ||
|
||
expect(noCache).toBe('dont cache'); | ||
|
||
const mustRevalidate = defaultHeaderInterpreter({ | ||
[Header.CacheControl]: 'must-revalidate' | ||
}); | ||
|
||
expect(mustRevalidate).toBe(0); | ||
}); | ||
|
||
it('tests with maxAge header for 10 seconds', () => { | ||
const result = defaultHeaderInterpreter({ | ||
[Header.CacheControl]: 'max-age=10' | ||
}); | ||
|
||
// 10 Seconds in milliseconds | ||
expect(result).toBe(10 * 1000); | ||
}); | ||
}); |
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,42 @@ | ||
import { defaultHeaderInterpreter } from '../../src/header/interpreter'; | ||
import { Header } from '../../src/util/headers'; | ||
|
||
describe('test Expires header', () => { | ||
it('tests with future expires', () => { | ||
const date = new Date(new Date().getFullYear() + 1, 1, 1); | ||
|
||
const result = defaultHeaderInterpreter({ | ||
[Header.Expires]: date.toUTCString() | ||
}); | ||
|
||
const approx = date.getTime() - Date.now(); | ||
|
||
expect(typeof result).toBe('number'); | ||
|
||
if (typeof result !== 'number') { | ||
return expect(true).toBeFalsy(); | ||
} | ||
|
||
// the result should be what the date is in milliseconds | ||
// minus the actual epoch milliseconds | ||
expect(Math.abs(result - approx)).toBeLessThanOrEqual(1); | ||
}); | ||
|
||
it('expects Expires to be used when invalid Cache-Control is provided', () => { | ||
const result = defaultHeaderInterpreter({ | ||
[Header.CacheControl]: '', | ||
[Header.Expires]: new Date(new Date().getFullYear() - 1, 1, 1).toUTCString() | ||
}); | ||
|
||
expect(result).toBe('dont cache'); | ||
}); | ||
|
||
it('tests with past expires', () => { | ||
const result = defaultHeaderInterpreter({ | ||
[Header.Expires]: new Date(new Date().getFullYear() - 1, 1, 1).toUTCString() | ||
}); | ||
|
||
// Past means cache invalid | ||
expect(result).toBe('dont cache'); | ||
}); | ||
}); |
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