Skip to content

Commit

Permalink
test: write tests for the provider
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 27, 2020
1 parent 91b774d commit a93a758
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion npm-audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5 class="card-title">
<div class="card">
<div class="card-body">
<h5 class="card-title">
July 27th 2020, 5:52:49 pm
July 27th 2020, 6:01:02 pm
</h5>
<p class="card-text">Last updated</p>
</div>
Expand Down
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"author": "virk",
"license": "MIT",
"devDependencies": {
"@adonisjs/application": "^2.0.0",
"@adonisjs/core": "^5.0.0-preview-rc-1.9",
"@adonisjs/fold": "^6.3.5",
"@adonisjs/mrm-preset": "^2.4.0",
Expand Down
2 changes: 1 addition & 1 deletion providers/ShieldProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { IocContract } from '@adonisjs/fold'
import { ShieldMiddleware } from '../src/ShieldMiddleware'

/**
* Provider to register shield middleware
Expand All @@ -24,6 +23,7 @@ export default class ShieldProvider {
? this.container.use('Adonis/Core/View')
: undefined

const { ShieldMiddleware } = require('../src/ShieldMiddleware')
return new ShieldMiddleware(Config.get('shield', {}), Encryption, View)
})
}
Expand Down
Empty file added test/fixtures/config/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions test/fixtures/config/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const appKey = 'averylongrandomsecretkey'

export const logger = {
enabled: true,
name: 'adonisjs',
level: 'info',
}

export const http = {
cookie: {},
}
32 changes: 32 additions & 0 deletions test/shield-middleware.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* @adonisjs/events
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import test from 'japa'
import { join } from 'path'
import { Registrar, Ioc } from '@adonisjs/fold'
import { Application } from '@adonisjs/application/build/standalone'
import { ShieldMiddleware } from '../src/ShieldMiddleware'

test.group('Shield Provider', () => {
test('register shield provider', async (assert) => {
const ioc = new Ioc()
ioc.bind('Adonis/Core/Application', () => {
return new Application(join(__dirname, 'fixtures'), ioc, {}, {})
})

const registrar = new Registrar(ioc, join(__dirname, '..'))
await registrar.useProviders(['@adonisjs/core', './providers/ShieldProvider']).registerAndBoot()

assert.instanceOf(ioc.use('Adonis/Addons/ShieldMiddleware'), ShieldMiddleware)
assert.deepEqual(
ioc.use('Adonis/Addons/ShieldMiddleware'),
ioc.use('Adonis/Addons/ShieldMiddleware')
)
})
})

0 comments on commit a93a758

Please sign in to comment.