From 98c669b139783d5485bde9c7d620411cc3db738d Mon Sep 17 00:00:00 2001 From: Jeffrey Biles Date: Tue, 17 Mar 2020 13:20:49 -0700 Subject: [PATCH] Mirage factories + models + seeds + faker --- mirage/index.js | 41 ++++++++++++++++------------------ package.json | 1 + src/components/InboxScreen.vue | 2 +- yarn.lock | 5 +++++ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/mirage/index.js b/mirage/index.js index caf6d6e..308be38 100644 --- a/mirage/index.js +++ b/mirage/index.js @@ -1,29 +1,26 @@ -import { Server } from "miragejs" +import { Server, Model, Factory } from "miragejs" +import faker from 'faker'; new Server({ + models: { + email: Model + }, + factories: { + email: Factory.extend({ + subject(i) { + return `Email ${i}` + }, + body(){ + return faker.lorem.sentence() + } + }) + }, + seeds(server){ + server.createList('email', 10); + }, routes() { this.namespace = 'api'; - this.get('/emails', async () => { - return [{ - id: 1, - subject: 'First Steps', - body: 'Learning Vue with Vue 3, cool!', - read: false, - archived: false, - }, { - id: 2, - subject: 'Vue 3 - pretty cool', - body: 'Lots of really good features happening here', - read: false, - archived: false - }, { - id: 3, - subject: 'Do we have a released date?', - body: "I hear Q2 2020.", - read: true, - archived: false - }] - }, {timing: 2000}) + this.get('/emails', {timing: 2000}); } }) diff --git a/package.json b/package.json index 3dc1797..2f0c5a8 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@vue/cli-plugin-babel": "^4.2.0", "@vue/cli-service": "^4.2.0", "@vue/compiler-sfc": "^3.0.0-alpha.9", + "faker": "^4.1.0", "miragejs": "^0.1.35", "vue-cli-plugin-vue-next": "^0.0.4", "vue-template-compiler": "^2.6.11" diff --git a/src/components/InboxScreen.vue b/src/components/InboxScreen.vue index 1ba425b..3c78f5b 100644 --- a/src/components/InboxScreen.vue +++ b/src/components/InboxScreen.vue @@ -10,7 +10,7 @@ export default { async setup(props, {attrs, slots}){ let response = await fetch('/api/emails'); - let emails = await response.json(); + let {emails} = await response.json(); return {emails} }, diff --git a/yarn.lock b/yarn.lock index 1b3faa5..4a8f346 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3235,6 +3235,11 @@ fake-xml-http-request@^2.1.1: resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.1.tgz#279fdac235840d7a4dff77d98ec44bce9fc690a6" integrity sha512-Kn2WYYS6cDBS5jq/voOfSGCA0TafOYAUPbEp8mUVpD/DVV5bQIDjlq+MLLvNUokkbTpjBVlLDaM5PnX+PwZMlw== +faker@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" + integrity sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8= + fast-deep-equal@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"