Skip to content

Commit

Permalink
Merge pull request #137 from MaurizioPz/#133
Browse files Browse the repository at this point in the history
Added tests for ETag
  • Loading branch information
v 1 r t l committed Oct 8, 2020
2 parents f103f74 + 61af441 commit d1b0442
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions __tests__/modules/etag.test.ts
@@ -1,4 +1,5 @@
import { eTag } from '../../packages/etag/src'
import { Stats } from 'fs'

describe('etag(entity)', () => {
it('should require an entity', () => {
Expand All @@ -18,4 +19,31 @@ describe('etag(entity)', () => {
expect(eTag('论')).toBe('"3-QkSKq8sXBjHL2tFAZknA2n6LYzM"')
expect(eTag('论', { weak: true })).toBe('W/"3-QkSKq8sXBjHL2tFAZknA2n6LYzM"')
})
it('should reject number entities', function () {
expect(() => eTag(<any>1)).toThrow('Received type number')
})
describe('Buffer', () => {
it('should work on empty', function () {
expect(eTag(Buffer.from(''))).toBe('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
})
it('should generate a strong ETag', () => {
expect(eTag(Buffer.from('beep boop'))).toBe('"9-fINXV39R1PCo05OqGqr7KIY9lCE"')
})
})
describe('fs.Stats', () => {
it('should generate a weak ETag', () => {
const stats = new Stats()
stats.mtime = new Date(Date.UTC(2020, 1, 1))
stats.size = 1024
expect(eTag(stats)).toBe('W/"16ffe0c0c00-400"')
})
})
describe('weak', () => {
it('should generate a weak ETag', () => {
expect(eTag('beep boop', { weak: true })).toBe('W/"9-fINXV39R1PCo05OqGqr7KIY9lCE"')
})
it('should generate a strong ETag', () => {
expect(eTag('beep boop', { weak: false })).toBe('"9-fINXV39R1PCo05OqGqr7KIY9lCE"')
})
})
})

0 comments on commit d1b0442

Please sign in to comment.