However, they are limited tools for developing APIs

Similar documents
User & Candidate APIs

Callbacks & Promises

donation-service-test

Agenda. JWT Node Libraries. Encoding & Decoding the Tokens. The Authenticate Route. Securing the API with a JWT Strategy. Testing the Secured API

JSON Evaluation. User Store

Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Produced by. Agile Software Development. Eamonn de Leastar

WorldSpace Attest Quick Start Guide

UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2015 EXAMINATIONS. CSC309H1 F Programming on the Web Instructor: Ahmed Shah Mashiyat

WooCommerce REST API Integration. October 27, 2018

JUnit and Play Framework

TECHNICAL GUIDE SSO JWT. At 360Learning, we don t make promises about technical solutions, we make commitments.

Using RESTfull services and remote SQL

Mobile Application Development

Practical Node.js. Building Real-World Scalable Web Apps. Apress* Azat Mardan

NODE.JS MOCK TEST NODE.JS MOCK TEST I

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

REST Admin API. Note: Version 9.X or higher is required for the support of REST API. Version /17

Getting Mean. Practical Perspective. Prof. Dr. Alejandro Zunino, Prof. Dr. Alfredo Teyseyre. ISISTAN Department of Computer Science UNICEN

Develop Mobile Front Ends Using Mobile Application Framework A - 2

Contact center integration with CRM. White paper and best practice for Daktela V6 setup with internal CRM system

CRM Service Wrapper User Guide

GitHub-Flask Documentation

Databases/JQuery AUGUST 1, 2018

Postman Quick Reference Guide Documentation

Making a POST Request Using Informatica Cloud REST API Connector

Trigger SMS API. API Documentation SPLIO - SPRING Contact and Campaign Trigger SMS API - EN v4.0.docx

DatabaseRESTAPI

Ninox API. Ninox API Page 1 of 15. Ninox Version Document version 1.0.0

Red Hat Fuse 7.1 Fuse Online Sample Integration Tutorials

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

Full Stack boot camp

Produced by. ICT-Skills Studio (2016) Higher Diploma in Science in Computer Science. John Fitzgerald

1/ , DNN Sharp

Using Dropbox with Node-RED

RESTful API Specification

Understanding RESTful APIs and documenting them with Swagger. Presented by: Tanya Perelmuter Date: 06/18/2018

PROCE55 Mobile: Web API App. Web API.

Step 1: Setup a Gitlab account

f5-icontrol-rest Documentation

Red Hat Fuse 7.2 Fuse Online Sample Integration Tutorials

Agenda. Simple precursor to Sessions. Sessions via Cookies in Hapi

CS193X: Web Programming Fundamentals

Serverless Microservices Are The New Black. Lorna Mitchell, IBM

Laszlo SZATHMARY University of Debrecen Faculty of Informatics

EMARSYS FOR MAGENTO 2

Front End Programming

Accessing the Progress OpenEdge AppServer. From Progress Rollbase. Using Object Script

Introducing DataPower GatewayScript. This feature is new for the 7.0 release.

Aim behind client server architecture Characteristics of client and server Types of architectures

#06 RPC & REST CLIENT/SERVER COMPUTING AND WEB TECHNOLOGIES

Quick Start Guide to gitlabr Jirka Lewandowski


CS 498RK FALL RESTFUL APIs

Red Hat JBoss Fuse 7.0-TP

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2016 EXAMINATIONS. CSC309H1 S Programming on the Web Instructor: Ahmed Shah Mashiyat

INF5750. Introduction to JavaScript and Node.js

Salesforce IoT REST API Getting Started Guide

About 1. Chapter 1: Getting started with odata 2. Remarks 2. Examples 2. Installation or Setup 2. Odata- The Best way to Rest 2

Big Fish ecommerce. BF Admin Module Payment Settings.doc

Guides SDL Server Documentation Document current as of 05/24/ :13 PM.

Protect Your API with OAuth 2. Rob Allen

MEAN Stack. 1. Introduction. 2. Foundation a. The Node.js framework b. Installing Node.js c. Using Node.js to execute scripts

CUSTOMER PORTAL. Connectors Guide

Tableau Automation Starter Kit:

Learning Objectives. Description. Your AU Expert(s) Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co.

Marketo Data Shield Setup Guide

SEEM4570 System Design and Implementation Lecture 03 JavaScript

A Guided Tour of Test Automation

GPII Security. Washington DC, November 2015

IN Development in Platform Ecosystems Lecture 3: json, ajax, APIs

RESTful Services. Distributed Enabling Platform

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

Bambu API Documentation

AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

Nasuni Data API Nasuni Corporation Boston, MA

Oracle Cloud Connecting Cloud Applications with Oracle Self-Service Integration Cloud Service

Smashing Node.JS: JavaScript Everywhere

70-487: Developing Windows Azure and Web Services

Kernel Gateway Documentation

Oracle Service Cloud Integration for Developers Ed 1

Node.js Training JavaScript. Richard richardrodger.com

Extra Notes - Data Stores & APIs - using MongoDB and native driver

Comprehensive AngularJS Programming (5 Days)

Nasuni Data API Nasuni Corporation Boston, MA

REST. Web-based APIs

EI-PaaS Node-RED Plug-ins User Manual

JavaScript Lecture 1

ShareSci: A Research Paper Networking Site

PayPal PLUS integration. Let our handbook be the fast track to achieve your business goals.

WhoWhenWhere. Project: WhoWhenWhere Date:

Hosting RESTful APIs. Key Terms:

Oracle Service Cloud Integration for Develope

2. QuickBooks Desktop Integration User Guides

sanction Documentation

Writing Web Apps in C++? Eric Bidelman, Google COSCUP / GNOME.Asia - Taipei, Taiwan August 14, 2010

Tools for Accessing REST APIs

DEVELOPING WEB AZURE AND WEB SERVICES MICROSOFT WINDOWS AZURE

Oracle Bots Nodes.js SDK: Controlling Smart Homes Using IFTTT Applets with Oracle Digital Assistant

Cloud Elements CRM Hub Provisioning and Usage Guide

Transcription:

Testing Endpoints

Automated Testing Using Postman or Insomnia are useful for exploring APIs However, they are limited tools for developing APIs Automated testing, where we manipulate the API as a Javascript client are considerably more useful For this, we need xunit test frameworks and associated test runner tools.

https://mochajs.org/

http://chaijs.com/

Assertion Styles

Assert Style The assert style is exposed through assert interface. This provides the classic assert-dot notation, similar to that packaged with node.js.

Installation Install mocha + chai as development dependencies

WebStorm Mocha Support A Mocha test runner will simplify running tests from within the IDE

Test Folder Package all tests in a separate high level test folder

First Unit Test A complete unit test suite Always passes (1 == 1) Uses the chai assertion library

Mocha Test Runner in Webstorm Convenient test runner, green for pass

Mocha Test Runner in Webstorm Red for fail

sync-request To keep unit tests simple, we can switch to synchronous mode. Although inefficient, this is not a concern for tests Simplified tests (no callbacks, promises etc..) more clearly communicates developer intent

First API Test Not really a test, as we have no assert yet.

test('get candidates', function () { const url = 'http://localhost:4000/api/candidates'; var res = request('get', url); const candidates = JSON.parse(res.getBody('utf8')); assert.equal(2, candidates.length); assert.equal(candidates[0].firstname, 'Lisa'); assert.equal(candidates[0].lastname, 'Simpson'); assert.equal(candidates[0].office, 'President'); assert.equal(candidates[1].firstname, 'Donald'); assert.equal(candidates[1].lastname, 'Simpson'); assert.equal(candidates[1].office, 'President'); }); Simple test to verify candidates preloaded by database seeding Not a sustainable approach to test data, but sufficient to get started { } "users": { "_model": "User", "homer": { "firstname": "Homer", "lastname": "Simpson", "email": "homer@simpson.com", "password": "secret" }, "marge": { "firstname": "Marge", "lastname": "Simpson", "email": "marge@simpson.com", "password": "secret" }, "bart": { "firstname": "Bart", "lastname": "Simpson", "email": "bart@simpson.com", "password": "secret" } }, "candidates": { "_model": "Candidate", "lisa": { "firstname": "Lisa", "lastname": "Simpson", "office": "President" }, "donald": { "firstname": "Donald", "lastname": "Simpson", "office": "President" } }, "donations": { "_model": "Donation", "one": { "amount": 40, "method": "paypal", "donor": "->users.bart", "candidate": "->candidates.lisa" }, "two": { "amount": 90, "method": "direct", "donor": "->users.marge", "candidate": "->candidates.lisa" }, "three": { "amount": 430, "method": "paypal", "donor": "->users.homer", "candidate": "->candidates.donald" } }

Get Single Candidate Endpoint Test test('get one candidate', function () { const allcandidatesurl = 'http://localhost:4000/api/candidates'; var res = request('get', allcandidatesurl); const candidates = JSON.parse(res.getBody('utf8')); const onecandidateurl = allcandidatesurl + '/' + candidates[0]._id; res = request('get', onecandidateurl); const onecandidate = JSON.parse(res.getBody('utf8')); assert.equal(onecandidate.firstname, 'Lisa'); assert.equal(onecandidate.lastname, 'Simpson'); assert.equal(onecandidate.office, 'President'); }); Get all Candidates first. Then use ID of first candidate to test get Single Candidate

Create Candidate Endpoint { method: 'POST', path: '/api/candidates', config: CandidatesApi.create }, exports.create = { auth: false, handler: function (request, reply) { const candidate = new Candidate(request.payload); candidate.save().then(newcandidate => { reply(newcandidate).code(201); }).catch(err => { reply(boom.badimplementation('error creating candidate')); }); }, }; Retrieve the candidate JSON from the payload Create and Save Mongo Object Return new candidate + http code 201 - Created - the valid response when a resource successfully added

Create Candidate Test test('create a candidate', function () { const candidatesurl = 'http://localhost:4000/api/candidates'; const newcandidate = { firstname: 'Barnie', lastname: 'Grumble', office: 'President', }; const res = request('post', candidatesurl, { json: newcandidate }); const returnedcandidate = JSON.parse(res.getBody('utf8')); assert.equal(returnedcandidate.firstname, 'Barnie'); assert.equal(returnedcandidate.lastname, 'Grumble'); assert.equal(returnedcandidate.office, 'President'); });

Delete a Candidate Endpoint { method: 'DELETE', path: '/api/candidates/{id}', config: CandidatesApi.deleteOne }, exports.deleteone = { auth: false, handler: function (request, reply) { Candidate.remove({ _id: request.params.id }).then(candidate => { reply(candidate).code(204); }).catch(err => { reply(boom.notfound('id not found')); }); }, };

Rest Endpoints Verbs Comparing database (sql) and HTTP Verbs

Action varies with HTTP Method

HTTP Response Codes