|
1 | 1 | 'use strict'
|
2 | 2 |
|
| 3 | +const seed = require('./index.js') |
| 4 | + |
3 | 5 | /* global describe, it */
|
4 |
| -describe('empty test suite', () => { |
5 |
| - it('write this test', () => { |
| 6 | +describe('should create items', () => { |
| 7 | + it('when given one model and one data item', (done) => { |
| 8 | + // Mocking out a sequelize model's create function |
| 9 | + // Users should use an actual sequelize model |
| 10 | + const Artist = { |
| 11 | + create: function () { |
| 12 | + done() |
| 13 | + } |
| 14 | + } |
| 15 | + |
| 16 | + // This shows the shape of the structure we are expecting |
| 17 | + const artists = { |
| 18 | + data: [ |
| 19 | + { |
| 20 | + name: 'Andrea Bocelli', |
| 21 | + genre: 'Opera' |
| 22 | + } |
| 23 | + ], |
| 24 | + model: Artist |
| 25 | + } |
| 26 | + |
| 27 | + // This shows how to call seedquelize |
| 28 | + seed([artists]) |
| 29 | + }) |
| 30 | + it('when given one model and multiple data items', function (done) { |
| 31 | + let currentDoneCount = 0 |
| 32 | + let finalDoneCount = 2 |
| 33 | + |
| 34 | + // Mocking out a sequelize model's create function |
| 35 | + // Users should use an actual sequelize model |
| 36 | + const Artist = { |
| 37 | + create: function () { |
| 38 | + checkIfDone() |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + // This shows the shape of the structure we are expecting |
| 43 | + const artists = { |
| 44 | + data: [ |
| 45 | + { |
| 46 | + name: 'Andrea Bocelli', |
| 47 | + genre: 'Opera' |
| 48 | + }, |
| 49 | + { |
| 50 | + name: 'Britney Spears', |
| 51 | + genre: 'Pop' |
| 52 | + }, |
| 53 | + { |
| 54 | + name: 'Lee Morgan', |
| 55 | + genre: 'Jazz' |
| 56 | + } |
| 57 | + ], |
| 58 | + model: Artist |
| 59 | + } |
| 60 | + |
| 61 | + // Only used in test to see if we've fired create enough times |
| 62 | + const checkIfDone = () => { |
| 63 | + if (currentDoneCount === finalDoneCount) { |
| 64 | + done() |
| 65 | + } else { |
| 66 | + currentDoneCount++ |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + // This shows how to call seedquelize |
| 71 | + seed([artists]) |
| 72 | + }) |
| 73 | + it('when given multiple models and multiple data items', function (done) { |
| 74 | + let currentDoneCount = 0 |
| 75 | + let finalDoneCount = 4 |
| 76 | + |
| 77 | + // Mocking out a sequelize model's create function |
| 78 | + // Users should use an actual sequelize model |
| 79 | + const Artist = { |
| 80 | + create: function () { |
| 81 | + checkIfDone() |
| 82 | + } |
| 83 | + } |
| 84 | + const User = { |
| 85 | + create: function () { |
| 86 | + checkIfDone() |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + // This shows the shape of the structure we are expecting |
| 91 | + const artists = { |
| 92 | + data: [ |
| 93 | + { |
| 94 | + name: 'Andrea Bocelli', |
| 95 | + genre: 'Opera' |
| 96 | + }, |
| 97 | + { |
| 98 | + name: 'Britney Spears', |
| 99 | + genre: 'Pop' |
| 100 | + }, |
| 101 | + { |
| 102 | + name: 'Lee Morgan', |
| 103 | + genre: 'Jazz' |
| 104 | + } |
| 105 | + ], |
| 106 | + model: Artist |
| 107 | + } |
| 108 | + |
| 109 | + const users = { |
| 110 | + data: [ |
| 111 | + { |
| 112 | + username: 'jimthedev', |
| 113 | + twitter: '@jimthedev' |
| 114 | + }, |
| 115 | + { |
| 116 | + username: 'jnessview', |
| 117 | + twitter: 'JNessView' |
| 118 | + } |
| 119 | + ], |
| 120 | + model: User |
| 121 | + } |
| 122 | + |
| 123 | + // Only used in test to see if we've fired create enough times |
| 124 | + const checkIfDone = () => { |
| 125 | + if (currentDoneCount === finalDoneCount) { |
| 126 | + done() |
| 127 | + } else { |
| 128 | + currentDoneCount++ |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + // This shows how to call seedquelize |
| 133 | + seed([ |
| 134 | + artists, |
| 135 | + users |
| 136 | + ]) |
6 | 137 | })
|
7 | 138 | })
|
0 commit comments