Skip to content

Commit

Permalink
test: fix breaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 16, 2021
1 parent 1e5c978 commit 1f223e2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions adonis-typings/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
declare module '@ioc:Adonis/Core/Validator' {
import { UUIDVersion } from 'validator/lib/isUUID'
import { default as validatorJs } from 'validator'
import { DateTime, DurationObjectUnits } from 'luxon'
import { DateTime, DurationObject } from 'luxon'
import { RequestContract } from '@ioc:Adonis/Core/Request'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { MultipartFileContract, FileValidationOptions } from '@ioc:Adonis/Core/BodyParser'
Expand Down Expand Up @@ -717,7 +717,7 @@ declare module '@ioc:Adonis/Core/Validator' {
/**
* The value of date must be after a given duration
*/
after(duration: number, unit: keyof DurationObjectUnits): Rule
after(duration: number, unit: keyof DurationObject): Rule

/**
* The value of date must be after a given date
Expand All @@ -735,7 +735,7 @@ declare module '@ioc:Adonis/Core/Validator' {
/**
* The value of date must be before a given duration
*/
before(duration: number, unit: keyof DurationObjectUnits): Rule
before(duration: number, unit: keyof DurationObject): Rule

/**
* The value of date must be before a given date
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"devDependencies": {
"@adonisjs/application": "^5.1.5",
"@adonisjs/bodyparser": "^8.0.0",
"@adonisjs/drive": "^2.0.2",
"@adonisjs/encryption": "^4.0.5",
"@adonisjs/http-server": "^5.5.1",
"@adonisjs/mrm-preset": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/Validations/date/helpers/offset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

import { DurationObjectUnits, DateTime } from 'luxon'
import { DurationObject, DateTime } from 'luxon'
import { ValidationRuntimeOptions } from '@ioc:Adonis/Core/Validator'
import { isRef, enforceDateTime } from '../../../Validator/helpers'

Expand All @@ -16,7 +16,7 @@ import { isRef, enforceDateTime } from '../../../Validator/helpers'
*/
export type CompileReturnType = {
operator: '>' | '<'
offset?: { duration: number; unit: keyof DurationObjectUnits; hasDayDuration: boolean }
offset?: { duration: number; unit: keyof DurationObject; hasDayDuration: boolean }
ref?: string
}

Expand Down
6 changes: 3 additions & 3 deletions test/validations/after.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import test from 'japa'
import { DateTime, DurationObjectUnits } from 'luxon'
import { DateTime, DurationObject } from 'luxon'
import { SchemaRef, ParsedRule } from '@ioc:Adonis/Core/Validator'

import { rules } from '../../src/Rules'
Expand All @@ -22,11 +22,11 @@ function compile(keyword: 'today' | 'tomorrow'): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(date: SchemaRef<DateTime>): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(interval: number, duration: keyof DurationObjectUnits): ParsedRule<any>
function compile(interval: number, duration: keyof DurationObject): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(
interval: number | SchemaRef<DateTime> | 'today' | 'tomorrow',
duration?: keyof DurationObjectUnits
duration?: keyof DurationObject
): ParsedRule<any> {
const { options } =
typeof interval === 'number'
Expand Down
6 changes: 3 additions & 3 deletions test/validations/before.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import test from 'japa'
import { DateTime, DurationObjectUnits } from 'luxon'
import { DateTime, DurationObject } from 'luxon'
import { SchemaRef, ParsedRule } from '@ioc:Adonis/Core/Validator'

import { rules } from '../../src/Rules'
Expand All @@ -22,11 +22,11 @@ function compile(keyword: 'today' | 'yesterday'): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(date: SchemaRef<DateTime>): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(interval: number, duration: keyof DurationObjectUnits): ParsedRule<any>
function compile(interval: number, duration: keyof DurationObject): ParsedRule<any>
// eslint-disable-next-line no-redeclare
function compile(
interval: number | SchemaRef<DateTime> | 'today' | 'yesterday',
duration?: keyof DurationObjectUnits
duration?: keyof DurationObject
): ParsedRule<any> {
const { options } =
typeof interval === 'number'
Expand Down
19 changes: 12 additions & 7 deletions test/validations/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
*/

import test from 'japa'
import { rules } from '../../src/Rules'
import { MessagesBag } from '../../src/MessagesBag'
import { ApiErrorReporter } from '../../src/ErrorReporter'

import { FileValidationOptions } from '@ioc:Adonis/Core/BodyParser'
import { File } from '@adonisjs/bodyparser/build/src/Multipart/File'

import { rules } from '../../src/Rules'
import { validate } from '../fixtures/rules/index'
import { MessagesBag } from '../../src/MessagesBag'
import { ApiErrorReporter } from '../../src/ErrorReporter'
import { file } from '../../src/Validations/primitives/file'

function compile(options: Partial<FileValidationOptions>) {
return file.compile('literal', 'file', rules['file'](options).options, {})
}

test.group('File', () => {
const multipartFile = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {})
const multipartFile = new File(
{ fieldName: 'avatar', clientName: 'avatar', headers: {} },
{},
{} as any
)
multipartFile.state = 'consumed'
multipartFile.size = 8
multipartFile.extname = 'jpg'
Expand Down Expand Up @@ -77,7 +82,7 @@ test.group('File', () => {
})

test('report error when size validation fails', (assert) => {
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {})
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {}, {} as any)
mp.state = 'consumed'
mp.size = 20
mp.extname = 'jpg'
Expand Down Expand Up @@ -106,7 +111,7 @@ test.group('File', () => {
})

test('report error when extension validation fails', (assert) => {
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {})
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {}, {} as any)
mp.state = 'consumed'
mp.size = 20
mp.extname = 'png'
Expand Down Expand Up @@ -135,7 +140,7 @@ test.group('File', () => {
})

test('work fine when field is a valid file', (assert) => {
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {})
const mp = new File({ fieldName: 'avatar', clientName: 'avatar', headers: {} }, {}, {} as any)
mp.state = 'consumed'
mp.size = 20
mp.extname = 'png'
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"files": [
"./node_modules/@adonisjs/application/build/adonis-typings/index.d.ts",
"./node_modules/@adonisjs/http-server/build/adonis-typings/index.d.ts",
"./node_modules/@adonisjs/drive/build/adonis-typings/index.d.ts",
"./node_modules/@adonisjs/bodyparser/build/adonis-typings/index.d.ts"
]
}

0 comments on commit 1f223e2

Please sign in to comment.