Quiz on Hooks, Mail, and Events

Test your understanding of hooks, mail, and events.

1

What is the purpose of validVendor in the code below?

const { hooks } = require('@adonisjs/ignitor')

hooks.after.providersBooted(() => {
  const Validator = use('Validator')
  const vendors = ['Dell', 'Apple', 'Lenovo']
  const validVendor = async (data, field, message, args, get) => {
    const value = get(data, field)
    if (!value) {
      return
    }
    if (!vendors.includes(value)) {
      throw `Invalid vendor` 
    }
  }
  Validator.extend('validVendor', validVendor)
})
A)

validVendor checks if the value of the field to be validated contains the invalid strings Dell, Apple, or Lenovo. If it does, we throw the error message.

B)

validVendor checks if the value of the field to be validated contains a value other than Dell, Apple, or Lenovo. If it does, we throw the error message.

C)

validVendor checks if the value is empty and if it is, we throw the error message.

D)

None of the above

Question 1 of 40 attempted

Get hands-on with 1200+ tech skills courses.