Skip to content

Commit

Permalink
Fix tests and Application bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-oc-mentorship committed Jan 24, 2022
1 parent 2db90b0 commit 7b7131b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 68 deletions.
57 changes: 18 additions & 39 deletions src/__mocks__/store.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* export default {
get: () => {
return Promise.resolve({
data: [{
"id": "47qAXb6fIm2zOKkLzMro",
"vat": "80",
"fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a",
"status": "pending",
"type": "Hôtel et logement",
"commentary": "séminaire billed",
"name": "encore",
"fileName": "preview-facture-free-201801-pdf-1.jpg",
"date": "2004-04-04",
"amount": 400,
"commentAdmin": "ok",
"email": "a@a",
"pct": 20
},
const mockedBills = {
list() {
return Promise.resolve([{
"id": "47qAXb6fIm2zOKkLzMro",
"vat": "80",
"fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a",
"status": "pending",
"type": "Hôtel et logement",
"commentary": "séminaire billed",
"name": "encore",
"fileName": "preview-facture-free-201801-pdf-1.jpg",
"date": "2004-04-04",
"amount": 400,
"commentAdmin": "ok",
"email": "a@a",
"pct": 20
},
{
"id": "BeKy5Mo4jkmdfPGYpTxZ",
"vat": "",
Expand Down Expand Up @@ -60,27 +59,7 @@
"commentary": "test2",
"type": "Restaurants et bars",
"fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=4df6ed2c-12c8-42a2-b013-346c1346f732"
}]
})
}
} */
const mockedBills = {
list() {
return Promise.resolve([{
"id": "47qAXb6fIm2zOKkLzMro",
"vat": "80",
"fileUrl": "https://firebasestorage.googleapis.com/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a",
"status": "pending",
"type": "Hôtel et logement",
"commentary": "séminaire billed",
"name": "encore",
"fileName": "preview-facture-free-201801-pdf-1.jpg",
"date": "2004-04-04",
"amount": 400,
"commentAdmin": "ok",
"email": "a@a",
"pct": 20
}])
}])

},
create(bill) {
Expand Down
43 changes: 18 additions & 25 deletions src/__tests__/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,15 @@ describe("Given I am a user connected as Admin", () => {
router()
window.onNavigate(ROUTES_PATH.Dashboard)
await waitFor(() => screen.getByText("Validations"))
const contentPending = await screen.getByText("En attente (1)")
expect(contentPending).toBeTruthy()
const contentRefused = await screen.getByText("Refusé (2)")
expect(contentRefused).toBeTruthy()
expect(screen.getByTestId("big-billed-icon")).toBeTruthy()
})

test("fetches bills from an API and fails with 404 message error", async () => {
jest.spyOn(mockStore, "bills")
mockStore.bills.mockImplementationOnce(() => {
return {
list : () => {
return Promise.reject(new Error("Erreur 404"))
}
}})
describe("When an error occurs on API", () => {
beforeEach(() => {
jest.spyOn(mockStore, "bills")
Object.defineProperty(
window,
'localStorage',
Expand All @@ -250,43 +248,38 @@ describe("Given I am a user connected as Admin", () => {
const root = document.createElement("div")
root.setAttribute("id", "root")
document.body.appendChild(root)

router()
})
test("fetches bills from an API and fails with 404 message error", async () => {

mockStore.bills.mockImplementationOnce(() => {
return {
list : () => {
return Promise.reject(new Error("Erreur 404"))
}
}})
window.onNavigate(ROUTES_PATH.Dashboard)
await new Promise(process.nextTick);
const message = await screen.getByText(/Erreur 404/)
expect(message).toBeTruthy()
})

test("fetches messages from an API and fails with 500 message error", async () => {
jest.spyOn(mockStore, "bills")

mockStore.bills.mockImplementationOnce(() => {
return {
list : () => {
return Promise.reject(new Error("Erreur 500"))
}
}})
Object.defineProperty(
window,
'localStorage',
{ value: localStorageMock }
)
window.localStorage.setItem('user', JSON.stringify({
type: 'Admin',
email: "a@a"
}))
const root = document.createElement("div")
root.setAttribute("id", "root")
document.body.appendChild(root)

router()

window.onNavigate(ROUTES_PATH.Dashboard)
await new Promise(process.nextTick);
const message = await screen.getByText(/Erreur 500/)
expect(message).toBeTruthy()
})
})

})
})

2 changes: 1 addition & 1 deletion src/__tests__/DashboardFormUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Given I am connected as an Admin and I am on Dashboard Page', () => {
expect(screen.getByText(bill.commentAdmin)).toBeTruthy()
})
})
describe('When acceptrefuseded bill is passed to DashboardUI', () => {
describe('When refused bill is passed to DashboardUI', () => {
test(('Then, it should show admin commentary'), () => {
const html = DashboardFormUI(billrefused)
document.body.innerHTML = html
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/Logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const bills = [{
"commentAdmin": "ok",
"email": "a@a",
"pct": 20,
"email": "[email protected]"
}]

describe('Given I am connected', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default class Login {
e.preventDefault()
const user = {
type: "Admin",
email: e.target.querySelector(`input[data-testid="admin-email-input"]`).value,
password: e.target.querySelector(`input[data-testid="admin-password-input"]`).value,
email: e.target.querySelector(`input[data-testid="employee-email-input"]`).value,
password: e.target.querySelector(`input[data-testid="employee-password-input"]`).value,
status: "connected"
}
this.localStorage.setItem("user", JSON.stringify(user))
Expand Down

0 comments on commit 7b7131b

Please sign in to comment.