Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created December 26, 2017 09:41
Show Gist options
  • Save dmitryshelomanov/7af55980923f34cc56d47a63eccb25ec to your computer and use it in GitHub Desktop.
Save dmitryshelomanov/7af55980923f34cc56d47a63eccb25ec to your computer and use it in GitHub Desktop.
import test from 'ava'
import { stub } from 'sinon'
import { Ctx } from '../../../../__TESTS__/koa-ctx'
import isZipFile from './is-zip-file'
/* eslint-disable prefer-destructuring */
/* eslint-disable no-param-reassign */
test.beforeEach((t) => {
t.context.ctx = new Ctx()
t.context.nextReturns = Math.random()
t.context.next = stub().resolves(t.context.nextReturns)
})
test('test is-sip-file util with zip file', async (t) => {
const ctx = t.context.ctx
const { next, nextReturns } = t.context
const files = {
archive: {
type: 'application/zip',
},
}
ctx.setRequest('files', files)
const rs = await isZipFile(ctx, next)
t.is(rs, nextReturns)
t.true(next.called)
})
test('test is-sip-file util with image file', async (t) => {
const ctx = t.context.ctx
const { next } = t.context
const files = {
archive: {
type: 'application/image',
},
}
ctx.setRequest('files', files)
await isZipFile(ctx, next)
t.false(next.called)
t.is(ctx.body, 'file size mus be type (zip)')
t.is(ctx.status, 201)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment