\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Giang.nd2508} \pdfinfo{ /Title (postman-script-2.pdf) /Creator (Cheatography) /Author (Giang.nd2508) /Subject (Postman Script 2 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{59C7E3} \definecolor{LightBackground}{HTML}{EAF8FB} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Postman Script 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Giang.nd2508} via \textcolor{DarkBackground}{\uline{cheatography.com/134606/cs/27869/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Giang.nd2508 \\ \uline{cheatography.com/giang-nd2508} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 7th May, 2021.\\ Updated 25th February, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Response Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{let res = \{ \newline "store": \{ \newline "book": {[} \newline \{ \newline "category": "reference", \newline "author": "Nigel Rees", \newline "title": "Sayings of the Century", \newline "price": 8.95 \newline \}, \newline \{ \newline "category": "fiction", \newline "author": "Evelyn Waugh", \newline "title": "Sword of Honour", \newline "price": 12.99 \newline \}, \newline \{ \newline "category": "fiction", \newline "author": "Herman Melville", \newline "title": "Moby Dick", \newline "isbn": "0-553-21311-3", \newline "price": 8.99 \newline \}, \newline \{ \newline "category": "fiction", \newline "author": "J. R. R. Tolkien", \newline "title": "The Lord of the Rings", \newline "isbn": "0-395-19395-8", \newline "price": 22.99 \newline \} \newline {]}, \newline "bicycle": \{ \newline "color": "red", \newline "price": 19.95 \newline \} \newline \} \newline \};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extract data}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{let firstAuthor = res.store.book{[}0{]}.author; // Nigel Rees \newline let lastAuthor = res.store.book{[}res.store.book.length - 1{]}.author; // J. R. R. Tolkien \newline \newline let firstBook = res.store.book{[}0{]}; \newline /{\emph{\{ \newline category: 'reference', \newline author: 'Nigel Rees', \newline title: 'Sayings of the Century', \newline price: 8.95 \newline \} \newline }}/ \newline \newline let books = res.store.book; \newline let titleList = {[}{]}; \newline books.forEach((element) =\textgreater{} \{ \newline if (element.price \textless{} 15 \&\& element.category === "fiction") \{ \newline \seqsplit{titleList.push(element.title);} \newline \} \newline \}); \newline // {[} 'Sword of Honour', 'Moby Dick' {]} \newline \newline let bookList = \_.filter(books, (element) =\textgreater{} \{ \newline return element.price \textless{} 15 \&\& element.category === "fiction"; \newline \}); \newline let titles = \_.map(bookList, \_.property("title")); \newline //or \newline let titles = \_.map(bookList, "title"); \newline console.log(titles); \newline // {[} 'Sword of Honour', 'Moby Dick' {]} \newline \newline let isbn = {[}{]}; \newline books.forEach((element) =\textgreater{} \{ \newline if (element.isbn !== undefined) \{ \newline isbn.push(element.isbn); \newline \} \newline \}); \newline //{[} '0-553-21311-3', '0-395-19395-8' {]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Working with time}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{var moment = require('moment'); \newline \newline now = moment(); \newline \newline // 07/05/2021 \newline console.log(now.format("DD/MM/YYYY")); \newline \newline // tăng 1 ngày và 1 giờ so với thời điểm hiện tại \newline next\_1day\_1hour = now.add(1, "d").add(1, "h"); \newline console.log(next\_1day\_1hour.format("DD/MM/YYYY HH:mm:ss")); \newline \newline // giảm 1 ngày so với thời điểm hiện tại \newline yesterday = now.subtract(1, "days"); \newline console.log(yesterday.format("DD/MM/YYYY")); \newline \newline //milisecond \newline console.log(moment().valueOf()); \newline \newline //second \newline console.log(moment().unix());} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Branching}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// Call request A \newline postman.setNextRequest("A"); \newline \newline // Stop \newline postman.setNextRequest(null);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Assertion}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{pm.test("name of the test", () =\textgreater{} \{ \newline //code to make assertion \newline \}); \newline \newline //skip test \newline pm.test.skip("name of the test", () =\textgreater{} \{ \newline //code to make assertion \newline \});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Get request information}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{request.name \newline //request A \newline \newline request.url \newline //https://postman-echo.com/post \newline \newline request.method \newline //POST \newline \newline request.headers \newline /{\emph{ \newline \{ \newline content-type: "application/json", \newline user-agent: "PostmanRuntime/7.28.4", \newline accept: "}}/{\emph{", \newline host: "postman-echo.com", \newline ... \newline \} \newline }}/ \newline \newline request.headers{[}'content-type'{]} \newline //application/json \newline \newline request.headers.cookie \newline //sails.sid=s\%3A\_\_IlvuQ-\_d3y8a2MCRW\_ZmNWay5zb\_OC.sMfNnx \newline \newline //Get body in json \newline pm.request.body.raw \newline /{\emph{ \newline \{ \newline phone: "0931831823", \newline code: "402839ouroiewr" \newline \} \newline }}/ \newline \newline //Get body in urlencoded \newline pm.request.body.urlencoded \newline //a=1\&b=2 \newline \newline //Get body in form-data \newline pm.request.body.formdata.get("name")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Chaijs}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{expect(object1).keyword(object2)}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Chain Keyword}}: to, be, been, is, that, which, and, has, have, with, at, of, same, but, does, still, also} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Support Keyword}}: {\bf{.not}}, .deep, .nested, .own, .ordered, .any, .all} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Action Keyword}}: {\bf{.a(type{[}, msg{]})}} .include(val{[}, msg{]}) .ok {\bf{.true}} .false .null .undefined .nan .exist .empty .equal(val{[}, msg{]}) {\bf{.eql(obj{[}, msg{]})}} .above(n{[}, msg{]}) .least(n{[}, msg{]}) .below(n{[}, msg{]}) .most(n{[}, msg{]} .....} \tn % Row Count 11 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{pm.expect(pm.response.code).eql(200);} \newline \newline pm.expect(res.store.book{[}0{]}.author).eql("Nigel Rees"); \newline \newline let firstAuthor = res.store.book{[}0{]}.author; \newline pm.expect(firstAuthor).to.eql("Nigel Rees"); \newline \newline pm.expect(res.store.book.length).above(3);; \newline \newline let testQuantity = res.store.book.length \textgreater{} 3; \newline pm.expect(testQuantity).true; \newline \newline const expect = require("chai").expect; \newline let obj = \{ \newline "category": "reference", \newline "author": "Nigel Rees", \newline "title": "Sayings of the Century", \newline "price": 8.95 \newline \} \newline pm.test("test first book", () =\textgreater{}\{ \newline let firstBook = res.store.book{[}0{]}; \newline \seqsplit{expect(firstBook).eql(obj);} \newline \}); \newline \newline \newline let books = res.store.book; \newline let titles = \_.map(books, \_.property("title")); \newline /{\emph{ \newline {[} \newline "Sayings of the Century", \newline "Sword of Honour", \newline "Moby Dick", \newline "The Lord of the Rings" \newline {]} \newline }}/ \newline expect(titles).include("The Lord of the Rings"); \newline titles.forEach((e) =\textgreater{} expect(e).eql("The Lord of the Rings")); \newline titles.forEach((e) =\textgreater{} expect(e).string("o"));} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Check schema}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{//response \newline \{ \newline "id": 1, \newline "firstName": "Vernon", \newline "lastName": "Harper", \newline "email": \seqsplit{"egestas.rhoncus.Proin@massaQuisqueporttitor.org"}, \newline "programme": "Financial Analysis", \newline "courses": {[} \newline "Accounting", \newline "Statistics" \newline {]} \newline \} \newline \newline \newline //Test \newline const schema = \{ \newline "type": "object", \newline "properties": \{ \newline "id": \{"type": "number"\}, \newline "firstName": \{"type": "string"\}, \newline "lastName": \{"type": "string"\}, \newline "email": \{"type": "string"\}, \newline "programme": \{"type": "string"\}, \newline "courses": \{"type": "array"\} \newline \}, \newline // Field nào là bắt buộc thì liệt kê ở phần require \newline "require": {[}"id", "courses"{]} \newline \}; \newline \newline pm.test("Validate schema", () =\textgreater{} \{ \newline \seqsplit{pm.response.to.have.jsonSchema(schema);} \newline \});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Newman}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{const newman = require("newman"); \newline const moment = \seqsplit{require("moment-timezone");} \newline \newline let date\_time = \seqsplit{moment().tz("Asia/Ho\_Chi\_Minh").format("DD-MM-YYYY\_HH-mm-ss");} \newline let fileName = \textbackslash{}`report-class1-\$\{date\_time\}\textbackslash{}`; \newline \newline newman.run( \newline \{ \newline collection: \seqsplit{require("./collections/class1.postman\_collection.json")}, \newline environment: \seqsplit{require("./env/Development.postman\_environment.json")}, \newline reporters: {[}"cli", "htmlextra"{]}, \newline reporter: \{ \newline htmlextra: \{ \newline export: \textbackslash{}`./test/report/\$\{fileName\}.html\textbackslash{}` \newline \} \newline \} \newline \}, \newline (err, summary) =\textgreater{} \{ \newline if (err) throw err; \newline \seqsplit{console.log(summary.run.failures);} \newline \} \newline );} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Get response information}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{pm.response.code \newline //200 \newline \newline pm.response.status \newline //OK \newline \newline pm.response.responseTime \newline //295 \newline \newline pm.response.responseSize \newline //633 \newline \newline //Get body in string \newline pm.response.text() \newline \newline //or \newline responseBody \newline // \{"args":\{\},"data":\{"phone":"093183","code":"4028ewr"\}\}" \newline \newline \newline //Get body in json \newline pm.response.json() \newline \newline //or \newline JSON.parse(responseBody) \newline /{\emph{ \newline \{ \newline "args": \{\}, \newline "data": \{ \newline "phone": "0931831823", \newline "code": "402839ouroiewr" \newline \} \newline \} \newline }}/ \newline \newline //Get response headers \newline responseHeaders \newline \newline /{\emph{ \newline \{ \newline "Date": "Wed, 13 Jul 2022 02:00:26 GMT", \newline "Content-Type": "application/json; charset=utf-8", \newline "Content-Length": "588", \newline "Connection": "keep-alive", \newline "ETag": "W/\textbackslash{}"24c-5jASVJWFOfv/weD+EO/h0FSWRLk\textbackslash{}"", \newline "Vary": "Accept-Encoding", \newline "set-cookie": \seqsplit{"sails.sid=s\%3ATHifsul4oQ2kju1Pf2KjQ;} Path=/; HttpOnly" \newline \} \newline }}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}