Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import request from "supertest";
import { expect } from "chai";
import { baseURL, HTTPStatusCode } from "../constants/constants";

export async function customPost(path, user) {
let credentials = {
username: "apiadmin",
password: "mgrx3JB74a2JfseCjvP2Msva",
};

const response = await request(baseURL)
.post(path)
.auth(credentials.username, credentials.password)
.send(user);
expect(response.status).to.eql(HTTPStatusCode.CREATED);
}
7 changes: 7 additions & 0 deletions constants/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const HTTPStatusCode = {
OK: 200,
CREATED: 201,
INTERNAL_SERVER_ERROR1: 500,
};

export const baseURL = "http://localhost:8000/wp-json/wp/v2";
48 changes: 48 additions & 0 deletions data/NewUserBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import NewUser from "./Newuser";
import faker from "faker";

let userName = faker.name.findName();
let email = faker.internet.email();
let password = faker.internet.password();
let firstName = faker.name.firstName();
let lastName = faker.name.lastName();

export default class NewUserBuilder {
constructor() {
this.user = new NewUser();
}

userName() {
this.user.username = userName;
return this;
}

password() {
this.user.password = password;
return this;
}

firstName() {
this.user.firstName = firstName;
return this;
}

lastName() {
this.user.lastName = lastName;
return this;
}

email() {
this.user.email = email;
return this;
}

role(role) {
this.user.roles = role;
return this;
}

build() {
return this.user;
}
}
10 changes: 10 additions & 0 deletions data/Newuser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default class NewUser {
constructor() {
this.username;
this.firstName;
this.roles;
this.lastName;
this.password;
this.email;
}
}
5 changes: 5 additions & 0 deletions data/SeedData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { customPost } from "../api/api";

export async function createUser(user) {
await customPost("/users", user);
}
13 changes: 13 additions & 0 deletions data/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var faker = require("faker");
import NewUserBuilder from "./NewUserBuilder";
export default class User {
static getUser() {
return new NewUserBuilder()
.userName(userName)
.email(email)
.password(password)
.firstName(firstName)
.lastName(lastName)
.build();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

156 changes: 156 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"mocha": "^8.0.1",
"taiko": "^1.0.14"
"taiko": "^1.0.14",
"supertest": "^4.0.2",
"faker": "^4.1.0"
},
"husky": {
"hooks": {
Expand Down
Loading