Skip to content

Commit

Permalink
Feature/e2e test pipeline (#136)
Browse files Browse the repository at this point in the history
* New build pipeline

dockerfile and pipeline

use e2e command

install before test

use cypress plug in

consolidate into one job

dockerignore non build files

remove unnecessary ignore

use node 16

* use multiple jobs

add action

* add dotnet tool restore step to build

* fix: bugs after machete-client

* e2e-tests: fix for pipeline and machete-client

* remove unsupported mask

* don't use bionic image

* disable cypress record video

* fix e2e tests

* remove non-doc comment
  • Loading branch information
esteban-gs authored Feb 10, 2023
1 parent d9e1b2c commit 55cceec
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 84 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.idea
.devcontainer
.vscode
cypress
dist
**.md
.github
test
20 changes: 19 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: [ master ]

jobs:
build:
unit-test:

runs-on: ubuntu-latest

Expand All @@ -34,3 +34,21 @@ jobs:
- run: npm ci
- run: npm run build --if-present
- run: npm run test-headless

ui-e2e-tests:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: "Start project compose services"
run: docker compose -f docker-compose.yml up -d
- name: "Wait for docker to finish building"
run: sleep 10

- name: Run cypress e2e tests
uses: cypress-io/github-action@v4
with:
config-file: cypress.json
wait-on: "http://localhost:4213/V2"
23 changes: 23 additions & 0 deletions ci.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-dotnet
WORKDIR /admin
RUN apt update && apt upgrade -y && apt install git
RUN git clone https://github.com/SavageLearning/Machete.git

WORKDIR /admin/Machete
RUN sed -i 's/localhost/sqlserver/g' Machete.Web/appsettings.json
RUN dotnet tool restore
RUN dotnet build --no-incremental
RUN dotnet publish -o output Machete.Web

FROM node:16-alpine as build-nodejs
WORKDIR /app
COPY ./ ./
RUN npm install
RUN npm run --silent build-prod

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
RUN mkdir -p /app/api/Content /app/api/Identity /app/api/dist
COPY --from=build-dotnet /admin/Machete/output/ /app/api
COPY --from=build-nodejs /app/dist /app/api/dist
WORKDIR /app/api
ENTRYPOINT ["dotnet","Machete.Web.dll"]
3 changes: 2 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"macheteApiUrl": "http://localhost:4213/api",
"macheteLegacyUrl": "http://localhost:4213"
},
"video": false
"video": false,
"screenshotOnRunFailure": true
}
33 changes: 33 additions & 0 deletions cypress/fixtures/employers/profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"data": {
"active": false,
"address1": "fake address",
"address2": null,
"blogparticipate": null,
"business": false,
"businessname": null,
"cellphone": null,
"city": "gotham city",
"driverslicense": null,
"email": "[email protected]",
"fax": null,
"isOnlineProfileComplete": null,
"licenseplate": null,
"name": "fake Employer",
"notes": null,
"onlineSigninID": "984fff15-93c5-41c4-b45d-2ed6f20f54f1",
"onlineSource": true,
"phone": "123-456-7891",
"receiveUpdates": false,
"referredby": 25,
"referredbyOther": null,
"returnCustomer": false,
"state": "WA",
"zipcode": "98122",
"createdby": "[email protected]",
"datecreated": "2023-01-16T01:05:00.857",
"dateupdated": "2023-01-16T01:21:24.0310004+00:00",
"id": 1,
"updatedby": "[email protected]"
}
}
18 changes: 4 additions & 14 deletions cypress/integration/employer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@ import { ENV_KEY_MACHETE_EMPLOYER, MACHETE_ADMIN } from "cypress/constants";
import { Employer } from "src/app/shared/models/employer";

describe("employers profile", () => {
before(() => {
cy.getEmployerProfile();
if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) === 0) {
// if new employer
cy.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
cy.visit("/employers");
cy.getEmployerProfile();
}
});

beforeEach(() => {
cy.apiLogin(MACHETE_ADMIN.user, MACHETE_ADMIN.password);
cy.visit("/employers");
cy.getEmployerProfile();

cy.apiGetEmployerProfile();
});

it("should display username", () => {
cy.visit("/employers");
const employerProfile = Cypress.env(ENV_KEY_MACHETE_EMPLOYER) as Employer;
cy.get(`[id="name"]`).should("have.value", employerProfile.name);
});

it("form should validate", () => {
cy.visit("/employers");
const employer = Cypress.env(ENV_KEY_MACHETE_EMPLOYER);

// name
Expand Down Expand Up @@ -94,6 +83,7 @@ describe("employers profile", () => {
});

it("should navigate to hire worker form on save", () => {
cy.visit("/employers");
const employer: Employer = Cypress.env(ENV_KEY_MACHETE_EMPLOYER);
cy.get("#name").should("contain.value", employer.name);
cy.get(`[type="submit"]`).should("exist").click();
Expand Down
21 changes: 14 additions & 7 deletions cypress/integration/hirer-portal/intro-confirm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { ENV_KEY_MACHETE_EMPLOYER, MACHETE_ADMIN, onlineOrderRoutes } from "cypress/constants";
import {
ENV_KEY_MACHETE_CONFIGS,
MACHETE_ADMIN,
onlineOrderRoutes,
} from "cypress/constants";
import { ConfigVM } from "machete-client";

const loadConfigs = () => Cypress.env(ENV_KEY_MACHETE_CONFIGS) as ConfigVM[];

describe("hirer portal - intro-comfirm - flow", () => {
before(() => {
cy.getMacheteConfigs();
});

beforeEach(() => {
cy.apiLogin(MACHETE_ADMIN.user, MACHETE_ADMIN.password);
cy.getEmployerProfile();
cy.apiGetEmployerProfile();

if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) == 0) {
// if new employer
console.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
}
cy.enableOnlineOrdersSetting(loadConfigs());
});

//#region intro-comfirm
Expand Down
9 changes: 1 addition & 8 deletions cypress/integration/hirer-portal/introduction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
ENV_KEY_MACHETE_EMPLOYER,
MACHETE_ADMIN,
onlineOrderRoutes,
} from "cypress/constants";

describe("hirer portal - introduction - flow", () => {
beforeEach(() => {
cy.apiLogin(MACHETE_ADMIN.user, MACHETE_ADMIN.password);
cy.getEmployerProfile();

if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) == 0) {
// if new employer
console.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
}
cy.apiGetEmployerProfile();
});

//#region intro
Expand Down
12 changes: 3 additions & 9 deletions cypress/integration/hirer-portal/order-confirm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ENV_KEY_ANY_SKILL,
ENV_KEY_MACHETE_EMPLOYER,
ENV_KEY_MACHETE_PAID_TRANSPORT_RULE,
MACHETE_ADMIN,
onlineOrderRoutes,
Expand All @@ -10,7 +9,7 @@ import {
generateWorkAssignmentsStub,
getExpectedCostForWorkerCount,
} from "cypress/utils";
import { Lookup } from "src/app/lookups/models/lookup";
import { LookupVM } from "machete-client";
import { TransportRule } from "src/app/online-orders/shared/models/transport-rule";
import { WorkAssignment } from "src/app/shared/models/work-assignment";
import { stepsToWorkAssignments } from "./work-assignments.spec";
Expand All @@ -19,7 +18,7 @@ let waInTest: WorkAssignment[];

const stepsToOrderConfirm = () => {
// arrange base state
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
if (anySkill === null || anySkill === undefined) throw new Error();
const paidTransportRule = Cypress.env(
ENV_KEY_MACHETE_PAID_TRANSPORT_RULE
Expand All @@ -46,12 +45,7 @@ describe("hirer portal - order confirm flow", () => {
cy.getMacheteScheduleRules();
cy.getMacheteTransportProviders();
cy.getMacheteLookups();
cy.getEmployerProfile();
if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) == 0) {
// if new employer
console.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
}
cy.apiGetEmployerProfile();
});

beforeEach(() => {
Expand Down
25 changes: 10 additions & 15 deletions cypress/integration/hirer-portal/work-assignments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
generateWorkOrderStub,
} from "cypress/utils/helpers";
import * as faker from "faker";
import { Lookup } from "src/app/lookups/models/lookup";
import { LookupVM } from "machete-client";
import { ScheduleRule } from "src/app/online-orders/shared/models/schedule-rule";
import { TransportProvider } from "src/app/online-orders/shared/models/transport-provider";
import { TransportRule } from "src/app/online-orders/shared/models/transport-rule";
Expand Down Expand Up @@ -73,12 +73,7 @@ describe("hirer portal - work-assignments - flow", () => {
cy.getFirstMachetePaidTransportRule();
cy.getMacheteScheduleRules();
cy.getMacheteTransportProviders();
cy.getEmployerProfile();
if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) == 0) {
// if new employer
console.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
}
cy.apiGetEmployerProfile();
cy.getMacheteLookups();
});

Expand Down Expand Up @@ -129,7 +124,7 @@ describe("hirer portal - work-assignments - flow", () => {
.should("not.have.attr", "disabled");
});
it("should not display add request if invalid", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
cy.get(WorkAssignmentSelectors.fieldHoursNeeded).type(
anySkill.minHour.toString()
);
Expand All @@ -155,7 +150,7 @@ describe("hirer portal - work-assignments - flow", () => {
);
});
it("should add request to list when valid and swtich to review tab", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
selectAnySkill(anySkill);
cy.get(WorkAssignmentSelectors.buttonAddCurrentJobToRequest).click();
cy.get(".p-tabview-nav-content ul li:first")
Expand All @@ -166,7 +161,7 @@ describe("hirer portal - work-assignments - flow", () => {
.contains(stringToTitleCase(anySkill.text_EN));
});
it("should show success message when request is added", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
selectAnySkill(anySkill);
cy.get(WorkAssignmentSelectors.buttonAddCurrentJobToRequest).click();
cy.get(`p-messages .p-message-summary`).contains(`Success!`);
Expand All @@ -175,7 +170,7 @@ describe("hirer portal - work-assignments - flow", () => {
);
});
it("should edit request", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
const uniqueValue = "MacheteRocks";
selectAnySkill(anySkill);
cy.get(WorkAssignmentSelectors.buttonAddCurrentJobToRequest).click();
Expand All @@ -189,7 +184,7 @@ describe("hirer portal - work-assignments - flow", () => {
cy.get(`tbody`).contains((anySkill.minHour + 1).toString());
});
it("should delete request", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
const uniqueValue = "MacheteRocks";
cy.get(WorkAssignmentSelectors.fieldAdditionalInfo).type(uniqueValue);
selectAnySkill(anySkill);
Expand All @@ -198,7 +193,7 @@ describe("hirer portal - work-assignments - flow", () => {
cy.get(`tbody`).should("not.contain", uniqueValue);
});
it("Add More Jobs should switch to blank form", () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
selectAnySkill(anySkill);
cy.get(WorkAssignmentSelectors.buttonAddCurrentJobToRequest).click();
cy.get(WorkAssignmentSelectors.buttonAddMoreJobs).click();
Expand All @@ -208,15 +203,15 @@ describe("hirer portal - work-assignments - flow", () => {
);
});
it(`Save and Continue should navigate to ${onlineOrderRoutes.orderConfirm}`, () => {
const anySkill: Lookup = Cypress.env(ENV_KEY_ANY_SKILL);
const anySkill: LookupVM = Cypress.env(ENV_KEY_ANY_SKILL);
selectAnySkill(anySkill);
cy.get(WorkAssignmentSelectors.buttonAddCurrentJobToRequest).click();
cy.get(WorkAssignmentSelectors.buttonSaveAndContinue).click();
cy.url().should("contain", onlineOrderRoutes.orderConfirm);
});
});

const selectAnySkill = (anySkill: Lookup) => {
const selectAnySkill = (anySkill: LookupVM) => {
cy.wait(REMOTE_TEST_WAIT_MS);
cy.get(WorkAssignmentSelectors.chooseJobsTab).click();
cy.get(WorkAssignmentSelectors.fieldChageSkillSelection).click();
Expand Down
7 changes: 1 addition & 6 deletions cypress/integration/hirer-portal/work-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ describe("hirer portal - work-orders - flow", () => {
cy.apiLogin(MACHETE_ADMIN.user, MACHETE_ADMIN.password);
cy.getMacheteTransportRules();
cy.getMacheteTransportProviders();
cy.getEmployerProfile();
if (Cypress.env(ENV_KEY_MACHETE_EMPLOYER) == 0) {
// if new employer
console.log(Cypress.env(ENV_KEY_MACHETE_EMPLOYER));
cy.fillOutEmployerProfile();
}
cy.apiGetEmployerProfile();
});

beforeEach(() => {
Expand Down
Loading

0 comments on commit 55cceec

Please sign in to comment.