This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's do an in-memory implementation for now. | |
const _todos = [] | |
export default class TodosRepository { | |
// Marking all methods async makes them return promises! | |
async find(query) { | |
const filtered = _todos.filter((todo) => { | |
// Check the user ID | |
if (todo.userId !== query.userId) | |
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assert from 'assert' | |
// Using object destructuring to make it look good. | |
export function makeTodosService({ | |
// "repository" is a fancy term to descibe an object | |
// that is used to retrieve data from a datasource - the actual | |
// data source does not matter. Could be a database, a REST API, | |
// or some IoT things like sensors or whatever. | |
todosRepository, | |
// We also want info about the user that is using the service, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Todos Service', function () { | |
beforeEach(() { | |
subject = makeTodosService({ | |
db: testDatabaseSomehow | |
}) | |
}) | |
it('works', async function () { | |
const todos = await subject.getTodos() | |
expect(todos.length).to.equal(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class TodosService { | |
constructor({ db }) { | |
this.db = db | |
} | |
getTodos() { | |
return this.db.query('select * from todos') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function makeTodosService ({ db }) { | |
return { | |
getTodos: () => { | |
return db.query('select * from todos') | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db from '../mydatabase' | |
export default { | |
getTodos: () => { | |
return db.query('select * from todos') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var app = express() | |
var session = require('express-session') | |
app.use(session({ | |
store: require('connect-session-knex')() | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const currentUser = { | |
id: 123, | |
name: 'Jeff' | |
} | |
const todosRepository = new TodosRepository() | |
const todosService = makeTodosService({ | |
todosRepository, | |
currentUser | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SkyClip | |
// - ReflectionHelper.cs | |
// -------------------------------------------------------------------- | |
// Author: Jeff Hansen <jeff@jeffijoe.com> | |
// Copyright (C) Jeff Hansen 2015. All rights reserved. | |
using System; | |
using System.Reflection; | |
namespace SkyClip.TestHelpers.Reflection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var setValidationStatusFor = function($field, isValid, errorMessage) { | |
var | |
$formgroup = $field.closest(".form-group"), | |
$helpBlock = $formgroup.find(".help-block"); | |
if (isValid) { | |
if ($helpBlock.data().hasShownErrorBefore) { | |
$helpBlock.text($helpBlock.data().originalText); | |
} | |
$formgroup.removeClass("has-error"); |