How to use the @adonisjs/fold.ioc.use function in @adonisjs/fold

To help you get started, we’ve selected a few @adonisjs/fold examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HigoRibeiro / adonis-gql / test / unit / server.spec.js View on Github external
test('global middleware execution', assert => {
    const Gql = ioc.use('Gql')

    class Middleware {
      async gqlHandle (resolve, root, args, context, info) {}
    }

    ioc.bind('Adonis/Middleware/Auth', () => {
      return new Middleware()
    })

    class UserMiddlewareController {
      user (parent, args, ctx) {}
      users (parent, args, ctx) {}
    }

    ioc.bind('App/Controllers/Gql/UserMiddlewareController', () => {
      return UserMiddlewareController
github adonisjs / adonis-lucid / test / unit / lucid-serializer.spec.js View on Github external
test('attach sideloaded data as meta', async (assert) => {
    class Profile extends Model {
    }

    class User extends Model {
      profile () {
        return this.hasOne(Profile)
      }
    }

    User._bootIfNotBooted()
    Profile._bootIfNotBooted()

    await ioc.use('Database').table('users').insert([{ username: 'virk' }, { username: 'nikk' }])
    await ioc.use('Database').table('profiles').insert([{ user_id: 1, profile_name: 'virk' }, { user_id: 2, profile_name: 'nikk' }])

    const users = await User.query().withCount('profile').paginate()

    const json = users.toJSON()
    assert.property(json, 'data')
    assert.isArray(json.data)
    assert.deepEqual(json.data[0].__meta__, { profile_count: helpers.formatNumber(1) })
    assert.equal(json.page, 1)
    assert.equal(json.total, 2)
    assert.equal(json.perPage, 20)
    assert.equal(json.lastPage, 1)
  })
github brainnit / adonisjs-scout / test / unit / searchable.spec.js View on Github external
it('searchableAs returns prefixed model table', () => {
    const model = new ModelStub()
    ModelStub._bootIfNotBooted()
    ioc.use('Config').set('scout.prefix', 'prefix_')
    expect(model.searchableAs()).toBe('prefix_posts')
  })
github duyluonglc / lucid-mongo / test / unit / factory.spec.js View on Github external
group.after(async () => {
    await helpers.dropCollections(ioc.use('Database'))
    ioc.use('Database').close()
    try {
      await fs.remove(path.join(__dirname, './tmp'))
    } catch (error) {
      if (process.platform !== 'win32' || error.code !== 'EBUSY') {
        throw error
      }
    }
  }).timeout(0)
github duyluonglc / lucid-mongo / test / unit / lucid-morph-one.spec.js View on Github external
group.before(async () => {
    ioc.singleton('Adonis/Src/Database', function () {
      const config = new Config()
      config.set('database', {
        connection: 'testing',
        testing: helpers.getConfig()
      })
      return new DatabaseManager(config)
    })
    ioc.alias('Adonis/Src/Database', 'Database')

    await fs.ensureDir(path.join(__dirname, './tmp'))
    await helpers.createCollections(ioc.use('Adonis/Src/Database'))
  })
github duyluonglc / lucid-mongo / test / unit / field-format.spec.js View on Github external
class User extends Model {
      static get geometries () {
        return ['location']
      }
    }
    User._bootIfNotBooted()
    const user = await User.create({
      location: {
        latitude: 1,
        longitude: 2
      }
    })
    assert.instanceOf(user.$attributes.location, GeoPoint)
    assert.equal(user.$attributes.location.latitude, 1)
    assert.equal(user.$attributes.location.longitude, 2)
    const newUser = await ioc.use('Database').collection('users').findOne()
    assert.instanceOf(newUser.location, Object)
    assert.equal(newUser.location.type, 'Point')
    assert.deepEqual(newUser.location.coordinates, [2, 1])
  })
github duyluonglc / lucid-mongo / test / unit / schema.spec.js View on Github external
collection.increments()
        })

        this.createCollection('schema_profile', (collection) => {
          collection.increments()
        })
      }
    }
    const userSchema = new UserSchema(ioc.use('Database'))
    userSchema.up()
    await userSchema.executeActions()
    const hasUsers = await userSchema.hasCollection('schema_users')
    const hasProfile = await userSchema.hasCollection('schema_profile')
    assert.isTrue(hasUsers)
    assert.isTrue(hasProfile)
    await ioc.use('Database').schema.dropCollection('schema_users')
    await ioc.use('Database').schema.dropCollection('schema_profile')
  })
github duyluonglc / lucid-mongo / test / unit / lucid-has-many-through.spec.js View on Github external
}
    }

    class Country extends Model {
      posts () {
        return this.manyThrough(User, 'posts')
      }
    }

    User._bootIfNotBooted()
    Country._bootIfNotBooted()
    Post._bootIfNotBooted()

    const rsCountry = await ioc.use('Database').collection('countries').insert({ name: 'India' })
    const rsUser = await ioc.use('Database').collection('users').insert({ country_id: rsCountry.insertedIds[0], username: 'virk' })
    await ioc.use('Database').collection('posts').insert({ user_id: rsUser.insertedIds[0], title: 'Adonis 101' })

    const countries = await Country.query().with('posts', (builder) => {
      builder.selectThrough('_id')
    }).fetch()

    assert.equal(countries.size(), 1)
    const country = countries.first()

    assert.instanceOf(country.getRelated('posts'), VanillaSerializer)
    assert.equal(country.getRelated('posts').size(), 1)
  })
})
github adonisjs / adonis-lucid / test / unit / lucid-relations.spec.js View on Github external
group.after(async () => {
    await helpers.dropTables(ioc.use('Adonis/Src/Database'))
    ioc.use('Database').close()
    try {
      await fs.remove(path.join(__dirname, './tmp'))
    } catch (error) {
      if (process.platform !== 'win32' || error.code !== 'EBUSY') {
        throw error
      }
    }
  }).timeout(0)
github rhwilr / adonis-bumblebee / src / Bumblebee / context.spec.js View on Github external
test('the TransformerAbstract can be importet from the ioc', async (assert) => {
    const TransformerAbstract = ioc.use('Adonis/Addons/Bumblebee/TransformerAbstract')

    class UserTransformer extends TransformerAbstract {
      transform (model) {
        return {
          id: model.id
        }
      }
    }

    let data = {id: 42}

    let transformed = await Bumblebee.create()
      .item(data)
      .transformWith(UserTransformer)
      .toArray()