Skip to content

Instantly share code, notes, and snippets.

View felippenardi's full-sized avatar

Felippe Nardi felippenardi

View GitHub Profile

Testing an Angular $resource factory

Learn from live example how to test a $resource factory. What to test? What /not/ to test? When to use $resource? These questions will be answered here.

DEMO LINK

Let's start with a brief review.

What is $resource and when to use it?

The $resource is an Angular Service that makes it really easy to setup CRUD operations with RESTful APIs. If you have a /api/posts/ , this is all the code you need to setup http operations for POST, PUT, DELETE and GET:

@felippenardi
felippenardi / guide.md
Last active July 25, 2018 17:35 — forked from swalkinshaw/tutorial.md
GraphQL API Design Guide

Guide: GraphQL API Design

This guide was created by VTEX for internal purposes inspired by Shopify's GraphQL API Tutorial.

Error Handling

There is no official GraphQL guidelines for handling errors, so we are stabilishing our own.

@felippenardi
felippenardi / run_eslint.sh
Last active February 14, 2022 12:02
Shell script to Run Eslint only on modified files
#!/bin/bash
CHANGED_FILES=`git diff origin/master...HEAD --name-only`
node_modules/eslint/bin/eslint.js -f json $CHANGED_FILES --quiet | node_modules/eslines/index.js --quiet
if [[ $? != 0 ]] ; then
echo "Fix style violations"
exit 1
fi
echo "All changed files are good"
const twoFactorMachine = {
two_factor: {
id: 'two_factor',
onEntry: ['checkTwoFactorSettings'],
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{ target: 'setup', cond: 'needsToSetupTwoFactor' },
const twoFactorMachine = {
two_factor: {
id: 'two_factor',
onEntry: ['checkTwoFactorSettings'],
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{ target: 'setup', cond: 'needsToSetupTwoFactor' },
const twoFactorMachine = {
two_factor: {
id: 'two_factor',
onEntry: ['checkTwoFactorSettings'],
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{ target: 'setup', cond: 'needsToSetupTwoFactor' },
@felippenardi
felippenardi / home.json
Last active September 4, 2019 17:01
git.io/home-json-example
{
"store.home": {
"blocks": [
"info-card#principal",
"info-card#bottom",
"shelf"
]
},
"info-card#principal": {
@felippenardi
felippenardi / machine.js
Created September 20, 2019 14:27
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@felippenardi
felippenardi / machine.js
Created February 1, 2020 22:53
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions