Skip to content

Instantly share code, notes, and snippets.

View intojs's full-sized avatar

Daniel Dughila intojs

View GitHub Profile
@intojs
intojs / product-utils-with-mocks.spec
Created December 5, 2017 22:21
Mocking in TypeScript - product-utils-with-mocks.spec
import { Product } from './Product';
import { Price } from './Price';
import { filterProductsByName, addPriceToProduct } from './product-utils';
import { getProductMock } from './Product.mock';
import { getPriceMock } from './Price.mock';
describe('product-utils', () => {
test('filterProductsByName', () => {
const puffy = getProductMock({name: 'Puffy'});
@intojs
intojs / Product.mock.ts
Created December 5, 2017 22:33
Mocking in TypeScript - Product.mock.ts
import { Product } from './Product';
const getDefaults = (): Product => ({
name: 'mock name',
description: 'mock description',
longDescription: 'mock long description',
imageOne: 'mock imageOne src',
imageTwo: 'mock imageTwo src',
imageThree: 'mock imageThree src',
price: null
@intojs
intojs / Price.mock.ts
Created December 5, 2017 22:34
Testing in TypeScript - Price.mock.ts
import { Price } from './Price';
const getDefaults = (): Price => ({
value: 1000,
currency: 'EUR',
vat: 190,
stringRepresentation: '1190 €'
});
export const getPriceMock = (p?: Partial<Price>): Price => ({
@intojs
intojs / puffy.ts
Last active December 5, 2017 22:50
Mocking in TypeScript - puffy.ts
import { getProductMock } from './Product.mock';
const puffy = getProductMock({name: 'Puffy'});
console.log(puffy.description, 'Will print mock description');
@intojs
intojs / gists.route.1.js
Created December 20, 2017 21:46
FP in Node.js - gists.route.1.js
import express from 'express';
import axios from 'axios';
import parse from 'parse-link-header';
export const gistsRoute = express
.Router()
.get('/', function (req, res, next) {
let gists = [];
axios.get('https://api.github.com/users/intojs/gists?per_page=2&page=1')
.then(function (response) {
@intojs
intojs / index.js
Last active December 20, 2017 21:47
FP in Node.js - index.js
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import {gistsRoute} from './gists.route.2';
const app = express();
const port = process.env.PORT || 3000;
const jsonParser = bodyParser.json();
@intojs
intojs / gists.route.2.js
Created December 20, 2017 22:00
FP in Node.js - gists.route.2.js
import express from 'express';
import {handleGistsRoute} from "./handle-gists.4";
const gistsUrl = 'https://api.github.com/users/intojs/gists?per_page=2&page=1';
export const gistsRoute = express
.Router()
.get('/', handleGistsRoute(gistsUrl));
@intojs
intojs / handle-gists.1.js
Created December 20, 2017 22:04
FP in Node.js - handle-gists.1.js
import axios from "axios";
import parse from 'parse-link-header';
export const handleGistsRouteFactory = (dependencies) => (gistsUrl) => (req, res, next) => {
const {
axios,
parse
} = dependencies;
let gists = [];
axios.get(gistsUrl)
@intojs
intojs / gists.route.1.js
Created December 20, 2017 22:30
FP in Node.js - curried handleGistsRouteFactory
export const handleGistsRouteFactory = (dependencies) => (gistsUrl) => (req, res, next) => {...
@intojs
intojs / handle-gists.2.js
Created December 20, 2017 22:48
FP in Node.js - handle-gists.2.js
import axios from "axios";
import parseLinkHeader from 'parse-link-header';
export const getDescription = (gist) => ({
description: gist.description,
url: gist.url
});
export const sortByName = (a, b) => {
const nameA = a.description.toUpperCase();