sanger/limber

View on GitHub
app/frontend/javascript/test_support/factories/resource_config.js

Summary

Maintainability
A
0 mins
Test Coverage
import resources from '@/javascript/shared/resources.js'

// Reads in the shared resources file and provides some friendly interfaces
export default class ResourceConfig {
  constructor(resource_name) {
    this.resource_config = resources.find((resource) => {
      return resource.resource === resource_name
    })
  }
  get invalid() {
    return this.resource_config === undefined
  }
  get attributes() {
    return Object.entries(this.resource_config.attributes).reduce((attributes, [name, options]) => {
      if (!(options instanceof Object)) {
        attributes.push(name)
      }
      return attributes
    }, [])
  }
  get associations() {
    return Object.entries(this.resource_config.attributes).reduce((attributes, [name, options]) => {
      if (options instanceof Object) {
        attributes.push(name)
      }
      return attributes
    }, [])
  }
}