How to use createReview method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

approve.test.ts

Source:approve.test.ts Github

copy

Full Screen

...37test("a review is successfully created with a PAT", async () => {38 apiMocks.getUser();39 apiMocks.getPull();40 apiMocks.getReviews();41 const createReview = apiMocks.createReview();42 await approve("gh-tok", ghContext());43 expect(createReview.isDone()).toBe(true);44});45test("a review is successfully created with an Actions token", async () => {46 apiMocks.getUser();47 apiMocks.getPull();48 apiMocks.getReviews();49 const createReview = apiMocks.createReview();50 await approve("gh-tok", ghContext());51 expect(createReview.isDone()).toBe(true);52});53test("when a review is successfully created with message", async () => {54 apiMocks.getUser();55 apiMocks.getPull();56 apiMocks.getReviews();57 const createReview = apiMocks.createReview();58 await approve("gh-tok", ghContext(), undefined, "Review body");59 expect(createReview.isDone()).toBe(true);60});61test("when a review is successfully created using pull-request-number", async () => {62 apiMocks.getUser();63 apiNock64 .get("/repos/hmarr/test/pulls/102")65 .reply(200, { head: { sha: "24c5451bbf1fb09caa3ac8024df4788aff4d4974" } });66 apiNock.get("/repos/hmarr/test/pulls/102/reviews").reply(200, []);67 const createReview = apiNock68 .post("/repos/hmarr/test/pulls/102/reviews")69 .reply(200, { id: 1 });70 await approve("gh-tok", new Context(), 102);71 expect(createReview.isDone()).toBe(true);72});73test("when a review has already been approved by current user", async () => {74 apiMocks.getUser();75 apiMocks.getPull();76 apiMocks.getReviews(200, [77 {78 user: { login: "hmarr" },79 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",80 state: "APPROVED",81 },82 ]);83 const createReview = apiMocks.createReview();84 await approve("gh-tok", ghContext());85 expect(createReview.isDone()).toBe(false);86 expect(core.info).toHaveBeenCalledWith(87 expect.stringContaining(88 "Current user already approved pull request #101, nothing to do"89 )90 );91});92test("when a review is pending", async () => {93 apiMocks.getUser();94 apiMocks.getPull();95 apiMocks.getReviews(200, [96 {97 user: { login: "hmarr" },98 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",99 state: "PENDING",100 },101 ]);102 const createReview = apiMocks.createReview();103 await approve("gh-tok", new Context(), 101);104 expect(createReview.isDone()).toBe(true);105});106test("when a review is dismissed", async () => {107 apiMocks.getUser();108 apiMocks.getPull();109 apiMocks.getReviews(200, [110 {111 user: { login: "hmarr" },112 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",113 state: "DISMISSED",114 },115 ]);116 const createReview = apiMocks.createReview();117 await approve("gh-tok", new Context(), 101);118 expect(createReview.isDone()).toBe(true);119});120test("when a review is not approved", async () => {121 apiMocks.getUser();122 apiMocks.getPull();123 apiMocks.getReviews(200, [124 {125 user: { login: "hmarr" },126 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",127 state: "CHANGES_REQUESTED",128 },129 ]);130 const createReview = apiMocks.createReview();131 await approve("gh-tok", new Context(), 101);132 expect(createReview.isDone()).toBe(true);133});134test("when a review is commented", async () => {135 apiMocks.getUser();136 apiMocks.getPull();137 apiMocks.getReviews(200, [138 {139 user: { login: "hmarr" },140 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",141 state: "COMMENTED",142 },143 ]);144 const createReview = apiMocks.createReview();145 await approve("gh-tok", new Context(), 101);146 expect(createReview.isDone()).toBe(true);147});148test("when an old commit has already been approved", async () => {149 apiMocks.getUser();150 apiMocks.getPull();151 apiMocks.getReviews(200, [152 {153 user: { login: "hmarr" },154 commit_id: "6a9ec7556f0a7fa5b49527a1eea4878b8a22d2e0",155 state: "APPROVED",156 },157 ]);158 const createReview = apiMocks.createReview();159 await approve("gh-tok", ghContext());160 expect(createReview.isDone()).toBe(true);161});162test("when a review has already been approved by another user", async () => {163 apiMocks.getUser();164 apiMocks.getPull();165 apiMocks.getReviews(200, [166 {167 user: { login: "some" },168 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",169 state: "APPROVED",170 },171 ]);172 const createReview = apiMocks.createReview();173 await approve("gh-tok", new Context(), 101);174 expect(createReview.isDone()).toBe(true);175});176test("when a review has already been approved by unknown user", async () => {177 apiMocks.getUser();178 apiMocks.getPull();179 apiMocks.getReviews(200, [180 {181 user: null,182 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",183 state: "APPROVED",184 },185 ]);186 const createReview = apiMocks.createReview();187 await approve("gh-tok", new Context(), 101);188 expect(createReview.isDone()).toBe(true);189});190test("when a review has been previously approved by user and but requests a re-review", async () => {191 apiMocks.getUser();192 apiMocks.getPull(200, {193 head: { sha: "24c5451bbf1fb09caa3ac8024df4788aff4d4974" },194 requested_reviewers: [{ login: "hmarr" }],195 });196 apiMocks.getReviews(200, [197 {198 user: { login: "some" },199 commit_id: "24c5451bbf1fb09caa3ac8024df4788aff4d4974",200 state: "APPROVED",201 },202 ]);203 const createReview = apiMocks.createReview();204 await approve("gh-tok", new Context(), 101);205 expect(createReview.isDone()).toBe(true);206});207test("without a pull request", async () => {208 const createReview = apiMocks.createReview();209 await approve("gh-tok", new Context());210 expect(createReview.isDone()).toBe(false);211 expect(core.setFailed).toHaveBeenCalledWith(212 expect.stringContaining("Make sure you're triggering this")213 );214});215test("when the token is invalid", async () => {216 apiMocks.getUser(401, { message: "Bad credentials" });217 apiMocks.getPull(401, { message: "Bad credentials" });218 apiMocks.getReviews(401, { message: "Bad credentials" });219 const createReview = apiMocks.createReview();220 await approve("gh-tok", ghContext());221 expect(createReview.isDone()).toBe(false);222 expect(core.setFailed).toHaveBeenCalledWith(223 expect.stringContaining("`github-token` input parameter")224 );225});226test("when the token doesn't have write permissions", async () => {227 apiMocks.getUser();228 apiMocks.getPull();229 apiMocks.getReviews();230 apiNock231 .post("/repos/hmarr/test/pulls/101/reviews")232 .reply(403, { message: "Resource not accessible by integration" });233 await approve("gh-tok", ghContext());234 expect(core.setFailed).toHaveBeenCalledWith(235 expect.stringContaining("pull_request_target")236 );237});238test("when a user tries to approve their own pull request", async () => {239 apiMocks.getUser();240 apiMocks.getPull();241 apiMocks.getReviews();242 apiNock243 .post("/repos/hmarr/test/pulls/101/reviews")244 .reply(422, { message: "Unprocessable Entity" });245 await approve("gh-tok", ghContext());246 expect(core.setFailed).toHaveBeenCalledWith(247 expect.stringContaining("same user account")248 );249});250test("when pull request does not exist or the token doesn't have access", async () => {251 apiMocks.getUser();252 apiMocks.getPull(404, { message: "Not Found" });253 apiMocks.getReviews(404, { message: "Not Found" });254 const createReview = apiMocks.createReview();255 await approve("gh-tok", ghContext());256 expect(createReview.isDone()).toBe(false);257 expect(core.setFailed).toHaveBeenCalledWith(258 expect.stringContaining("doesn't have access")259 );260});261test("when the token is read-only", async () => {262 apiMocks.getUser();263 apiMocks.getPull();264 apiMocks.getReviews();265 apiNock266 .post("/repos/hmarr/test/pulls/101/reviews")267 .reply(403, { message: "Not Authorized" });268 await approve("gh-tok", ghContext());...

Full Screen

Full Screen

CreateReview.ts

Source:CreateReview.ts Github

copy

Full Screen

1/* tslint:disable */2/* eslint-disable */3/**4 * Yext API5 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)6 *7 * The version of the OpenAPI document: 2.08 * 9 *10 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).11 * https://openapi-generator.tech12 * Do not edit the class manually.13 */14import { exists, mapValues } from '../runtime';15/**16 * 17 * @export18 * @interface CreateReview19 */20export interface CreateReview {21 /**22 * ID of the location associated with this review23 * @type {string}24 * @memberof CreateReview25 */26 locationId: string;27 /**28 * The name of the person who wrote the review.29 * @type {string}30 * @memberof CreateReview31 */32 authorName: string;33 /**34 * Normalized rating out of 5.35 * @type {number}36 * @memberof CreateReview37 */38 rating: number;39 /**40 * Content of the review.41 * @type {string}42 * @memberof CreateReview43 */44 content: string;45 /**46 * The email address of the person who wrote the review.47 * @type {string}48 * @memberof CreateReview49 */50 authorEmail?: string;51 /**52 * The current status of the review; only returned for First Party and External First Party reviews. Defaults to `QUARANTINED` when creating.53 * @type {string}54 * @memberof CreateReview55 */56 status?: CreateReviewStatusEnum;57 /**58 * (`YYYY-MM-DD` format)59 * If provided, the date you received the review from the customer. Defaults to the date the review was uploaded to Yext.60 * @type {Date}61 * @memberof CreateReview62 */63 date?: Date;64}65/**66* @export67* @enum {string}68*/69export enum CreateReviewStatusEnum {70 Live = 'LIVE',71 Quarantined = 'QUARANTINED',72 Removed = 'REMOVED'73}74export function CreateReviewFromJSON(json: any): CreateReview {75 return CreateReviewFromJSONTyped(json, false);76}77export function CreateReviewFromJSONTyped(json: any, ignoreDiscriminator: boolean): CreateReview {78 if ((json === undefined) || (json === null)) {79 return json;80 }81 return {82 83 'locationId': json['locationId'],84 'authorName': json['authorName'],85 'rating': json['rating'],86 'content': json['content'],87 'authorEmail': !exists(json, 'authorEmail') ? undefined : json['authorEmail'],88 'status': !exists(json, 'status') ? undefined : json['status'],89 'date': !exists(json, 'date') ? undefined : (new Date(json['date'])),90 };91}92export function CreateReviewToJSON(value?: CreateReview | null): any {93 if (value === undefined) {94 return undefined;95 }96 if (value === null) {97 return null;98 }99 return {100 101 'locationId': value.locationId,102 'authorName': value.authorName,103 'rating': value.rating,104 'content': value.content,105 'authorEmail': value.authorEmail,106 'status': value.status,107 'date': value.date === undefined ? undefined : (value.date.toISOString().substr(0,10)),108 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const createReview = require('./createReview');2const review = {3};4createReview(review).then((review) => {5 console.log(review);6});7const pact = require('pact-foundation/pact-node');8const path = require('path');9const createReview = (review) => {10 const pactifiedReview = pact.pactify(review);11 const opts = {12 dir: path.resolve(process.cwd(), 'pacts'),13 };14 .setup()15 .then(() => {16 return new Promise((resolve, reject) => {17 .verifyPact(opts)18 .then(() => {19 pact.mockService(opts).then((server) => {20 server.addInteraction({21 withRequest: {22 headers: {23 }24 },25 willRespondWith: {26 headers: {27 },28 }29 }).then(() => {30 resolve(review);31 });32 });33 });34 });35 });36};37module.exports = createReview;38const createReview = require('./createReview');39const review = {40};41describe("Pact", () => {42 it("should create a review", () => {43 return createReview(review).then((review) => {44 expect(review).toEqual(review);45 });46 });47});

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-node');2var review = pact.createReview();3review.addComment("This is a comment");4review.save();5var pact = require('pact-node');6var review = pact.createReview();7review.addComment("This is a comment");8review.save();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful