mirror of
https://github.com/koel/koel
synced 2024-11-28 15:00:42 +00:00
Use factoria
This commit is contained in:
parent
29f72a008d
commit
87f318a542
10 changed files with 24 additions and 34 deletions
|
@ -72,7 +72,7 @@
|
|||
"eslint-config-vue": "^2.0.1",
|
||||
"eslint-plugin-vue": "^1.0.0",
|
||||
"expect": "^21.2.1",
|
||||
"faker": "^4.1.0",
|
||||
"factoria": "^1.0.1",
|
||||
"font-awesome": "^4.7.0",
|
||||
"jsdom": "^11.5.1",
|
||||
"jsdom-global": "^3.0.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import factory from '.'
|
||||
import factory from 'factoria'
|
||||
|
||||
export default () => {
|
||||
export default faker => {
|
||||
const artist = factory('artist')
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default () => ({
|
||||
export default faker => ({
|
||||
id: faker.random.number(),
|
||||
name: faker.name.findName(),
|
||||
info: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import factory from 'factoria'
|
||||
import artist from './artist'
|
||||
import album from './album'
|
||||
import song from './song'
|
||||
|
@ -5,28 +6,12 @@ import video from './video'
|
|||
import playlist from './playlist'
|
||||
import user from './user'
|
||||
|
||||
const models = { artist, album, song, video, playlist, user }
|
||||
|
||||
const factory = (model, count = 1, overrides = {}) => {
|
||||
if (!(model in models)) {
|
||||
throw new Error(`Model \`${model}\` not found`)
|
||||
}
|
||||
|
||||
if (typeof count === 'object') {
|
||||
return factory(model, 1, count)
|
||||
}
|
||||
|
||||
if (count === 1) {
|
||||
return _.assign(models[model](), overrides)
|
||||
} else {
|
||||
return [...(function* () {
|
||||
let i = 0
|
||||
while (i < count) {
|
||||
yield _.assign(models[model](), overrides)
|
||||
++i
|
||||
}
|
||||
})()]
|
||||
}
|
||||
}
|
||||
factory
|
||||
.define('artist', faker => artist(faker))
|
||||
.define('album', faker => album(faker))
|
||||
.define('song', faker => song(faker))
|
||||
.define('video', faker => video(faker))
|
||||
.define('playlist', faker => playlist(faker))
|
||||
.define('user', faker => user(faker))
|
||||
|
||||
export default factory
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import factory from '.'
|
||||
import factory from 'factoria'
|
||||
|
||||
export default () => ({
|
||||
export default faker => ({
|
||||
id: faker.random.number(),
|
||||
name: faker.random.word(),
|
||||
songs: factory('song', 10)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import md5 from 'blueimp-md5'
|
||||
import factory from '.'
|
||||
import factory from 'factoria'
|
||||
import crypto from 'crypto'
|
||||
|
||||
export default () => {
|
||||
export default faker => {
|
||||
const artist = factory('artist')
|
||||
const album = factory('album', {
|
||||
artist,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default () => ({
|
||||
export default faker => ({
|
||||
id: faker.random.number(),
|
||||
name: faker.name.findName(),
|
||||
email: faker.internet.email(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default () => ({
|
||||
export default faker => ({
|
||||
id: {
|
||||
videoId: faker.random.alphaNumeric()
|
||||
},
|
||||
|
|
|
@ -8,7 +8,6 @@ require('chai').should()
|
|||
|
||||
// make common utils available globally as well
|
||||
global.Vue = require('vue')
|
||||
global.faker = require('faker')
|
||||
global.expect = require('expect')
|
||||
global.sinon = require('sinon')
|
||||
global._ = require('lodash')
|
||||
|
|
|
@ -2778,6 +2778,12 @@ extsprintf@1.3.0, extsprintf@^1.2.0:
|
|||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
|
||||
|
||||
factoria@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/factoria/-/factoria-1.0.1.tgz#a2a08d688809c46d8e55c53b76b2a3b0c3d0b4ce"
|
||||
dependencies:
|
||||
faker "^4.1.0"
|
||||
|
||||
faker@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f"
|
||||
|
|
Loading…
Reference in a new issue