Skip to content

Commit

Permalink
test: cover repl binding and health check registration cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Oct 13, 2020
1 parent 606726f commit feba3dd
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 16 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">
October 13th 2020, 8:41:38 am
October 13th 2020, 8:51:20 am
</h5>
<p class="card-text">Last updated</p>
</div>
Expand Down
101 changes: 101 additions & 0 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 @@ -47,6 +47,7 @@
"devDependencies": {
"@adonisjs/core": "^5.0.2-beta-rc-6",
"@adonisjs/mrm-preset": "^2.4.0",
"@adonisjs/repl": "^1.1.2",
"@adonisjs/require-ts": "^1.0.4",
"@poppinss/dev-utils": "^1.0.11",
"@types/node": "^14.11.8",
Expand Down
5 changes: 4 additions & 1 deletion providers/RedisProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export default class RedisProvider {
return
}

require('../src/Bindings/Repl')(this.app)
this.app.container.with(['Adonis/Addons/Repl'], (Repl) => {
const { defineReplBindings } = require('../src/Bindings/Repl')
defineReplBindings(this.app, Repl)
})
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Bindings/Repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
* file that was distributed with this source code.
*/

import { ReplContract } from '@ioc:Adonis/Addons/Repl'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

/**
* Defune repl bindings. The method must be invoked when application environment
* is set to repl.
*/
export default function defineReplBindings(application: ApplicationContract) {
const Repl = application.container.use('Adonis/Addons/Repl')

export function defineReplBindings(application: ApplicationContract, Repl: ReplContract) {
Repl.addMethod(
'loadRedis',
(repl) => {
Expand Down
45 changes: 37 additions & 8 deletions test/redis-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { RedisManager } from '../src/RedisManager'

const fs = new Filesystem(join(__dirname, 'app'))

async function setup(redisConfig: any) {
async function setup(environment: 'web' | 'repl', redisConfig: any) {
await fs.add('.env', '')
await fs.add(
'config/app.ts',
Expand All @@ -37,8 +37,8 @@ async function setup(redisConfig: any) {
`
)

const app = new Application(fs.basePath, 'web', {
providers: ['@adonisjs/core', '../../providers/RedisProvider'],
const app = new Application(fs.basePath, environment, {
providers: ['@adonisjs/core', '@adonisjs/repl', '../../providers/RedisProvider'],
})

app.setup()
Expand All @@ -54,7 +54,7 @@ test.group('Redis Provider', (group) => {
})

test('register redis provider', async (assert) => {
const app = await setup({
const app = await setup('web', {
connection: 'local',
connections: {
local: {},
Expand All @@ -72,7 +72,7 @@ test.group('Redis Provider', (group) => {
assert.plan(1)

try {
await setup({})
await setup('web', {})
} catch (error) {
assert.equal(
error.message,
Expand All @@ -85,7 +85,7 @@ test.group('Redis Provider', (group) => {
assert.plan(1)

try {
await setup({})
await setup('web', {})
} catch (error) {
assert.equal(
error.message,
Expand All @@ -98,7 +98,7 @@ test.group('Redis Provider', (group) => {
assert.plan(1)

try {
await setup({
await setup('web', {
connection: 'local',
})
} catch (error) {
Expand All @@ -113,7 +113,7 @@ test.group('Redis Provider', (group) => {
assert.plan(1)

try {
await setup({
await setup('web', {
connection: 'local',
connections: {},
})
Expand All @@ -124,4 +124,33 @@ test.group('Redis Provider', (group) => {
)
}
})

test('define repl bindings', async (assert) => {
const app = await setup('repl', {
connection: 'local',
connections: {
local: {},
},
})

assert.property(app.container.use('Adonis/Addons/Repl')['customMethods'], 'loadRedis')
assert.isFunction(app.container.use('Adonis/Addons/Repl')['customMethods']['loadRedis'].handler)
})

test('define health checks', async (assert) => {
const app = await setup('web', {
connection: 'local',
connections: {
local: {
healthCheck: true,
},
},
})

assert.property(app.container.use('Adonis/Core/HealthCheck')['healthCheckers'], 'redis')
assert.equal(
app.container.use('Adonis/Core/HealthCheck')['healthCheckers'].redis,
'Adonis/Addons/Redis'
)
})
})
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./node_modules/@adonisjs/mrm-preset/_tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true
},
"files": ["./node_modules/@adonisjs/core/build/adonis-typings/index.d.ts"]
"skipLibCheck": true,
"types": ["@adonisjs/core", "@adonisjs/repl", "@types/node"]
}
}

0 comments on commit feba3dd

Please sign in to comment.