Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Create a job with the same name', async assert => {
await ace.call('make:job', { name: 'Test' })
const filePath = path.join(__dirname, '../../app/Jobs/Test.js')
assert.isTrue(fs.existsSync(filePath))
fs.unlinkSync(filePath)
})
})
test('create a schema file', async assert => {
await ace.call('gql:schema', { name: 'Post' })
const schema = fs.readFileSync('app/Schemas/Post.graphql', 'utf-8')
assert.equal(schema, getSchemaContent())
})
test('kue:listen', async assert => {
const Kue = use('Adonis/Addons/Kue')
const Job = ioc.use('App/GoodJob')
await ace.call('kue:listen')
const data = { test: 'data' }
const job = Kue.dispatch(Job.key, data)
const result = await job.result
assert.equal(result, 'test result')
assert.equal(job.type, Job.key)
assert.equal(job.data, data)
})
test('create a directive file', async assert => {
await ace.call('gql:directive', { name: 'Deprecated' })
const directive = fs.readFileSync(
'app/Directives/DeprecatedDirective.js',
'utf-8'
)
assert.equal(directive, getDirectiveContent())
})
test('skip when there is nothing to rollback', async (assert) => {
ace.addCommand(MigrationRollback)
const result = await ace.call('migration:rollback')
assert.deepEqual(result, { migrated: [], status: 'skipped', queries: undefined })
})
test('acl:role', async (assert) => {
await ace.call('acl:role', {
slug: 'administrator',
name: 'Administrator',
description: 'Administrator Role Description'
}, {
permissions: 'create_users,edit_users,delete_users'
})
const Role = use('Adonis/Acl/Role')
const role = await Role.findBy('name', 'Administrator')
const permissions = await role.getPermissions()
assert.equal(role.slug, 'administrator')
assert.equal(role.name, 'Administrator')
assert.equal(role.description, 'Administrator Role Description')
assert.includeMembers(permissions, [
'create_users', 'edit_users', 'delete_users'
])
})
})
}
}
module.exports = IndexKeeper
`)
await fs.outputFile(path.join(__dirname, 'app/Models/IndexKeepers/bar.js'), `
class IndexKeeper {
up () {
(global).stack.push('bar')
}
}
module.exports = IndexKeeper
`)
await ace.call('scout:up', {}, { files: 'foo.js' })
expect(global.stack).toContainEqual('foo')
})
})
up () {
this.createTable('schema_users', (table) => {
table.increments()
table.string('username')
})
}
down () {
this.drop('schema_users')
}
}
module.exports = User
`)
await ace.call('migration:run')
const result = await ace.call('migration:rollback', {}, { log: true })
assert.isArray(result.queries)
})
})
ace.addCommand(MigrationRun)
await fs.writeFile(path.join(__dirname, 'database/migrations/User.js'), `
const Schema = use('Schema')
class User extends Schema {
up () {
this.createCollection('schema_users', (collection) => {
collection.increments()
collection.string('username')
})
}
}
module.exports = User
`)
const result = await ace.call('migration:run')
assert.deepEqual(result, { migrated: ['User'], status: 'completed', queries: undefined })
const migrations = await ioc.use('Database').collection('adonis_schema').find()
assert.lengthOf(migrations, 1)
assert.equal(migrations[0].batch, 1)
assert.equal(migrations[0].name, 'User')
})
async handle (args, { log, force, silent, seed, keepAlive }) {
this._validateState(force)
if (keepAlive) {
this.migration.keepAlive()
}
await ace.call('migration:reset', {}, { log, force, silent })
await ace.call('migration:run', {}, { log, force, silent, seed, keepAlive })
}
}