Fakultas Ilmu Komputer UI

Commit 3c0b76e2 authored by Michael Wiryadinata Halim's avatar Michael Wiryadinata Halim
Browse files

Merge branch 'PBI-9-kelola_transaksi' into 'staging'

Pbi 9 kelola transaksi

See merge request !42
parents 90d6f5d5 e7430701
Pipeline #42631 passed with stages
in 12 minutes and 20 seconds
......@@ -10,20 +10,67 @@ beforeEach(() => {
afterEach(cleanup);
test("Test detail pengguna renders", async () => {
fetch.mockResponseOnce(
JSON.stringify({
id: "663392ac-1dd6-462b-9301-a19c1287cefd",
username: "dummyuser",
full_name: "Dummy User",
phone_number: "+6285212345678",
address: "Jl. Dummy No.1",
neighborhood: "000",
hamlet: "000",
urban_village: "Dummy Urban Village",
sub_district: "Dummy Sub-District",
profile_picture: null,
})
);
fetch
.once(
JSON.stringify({
count: 17,
next:
"https://industripilar-staging.herokuapp.com/transactions/?page=2",
previous: null,
results: [
{
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",
shipping_sub_district: "Dummy Sub-District",
transaction_items: [
{
id: "37f0298c-2e8a-4ab0-a094-e9177ddc60c4",
product: "3d403cd3-e356-4c15-9a86-8843333e2778",
product_code: "5VK6TY",
product_name: "produk barang",
product_price: "50000.00",
quantity: 7,
},
],
transaction_item_subtotal: "350000.00",
shipping_costs: "15000.00",
payment_method: "TRF",
readable_payment_method: "Transfer",
donation: "5000.00",
transaction_status: "002",
readable_transaction_status: "Waiting for seller confirmation",
proof_of_payment: null,
user_bank_account_name: "test",
user_bank_account_number: "1232131241321",
created_at: "2020-04-18T10:59:42.074386+07:00",
updated_at: "2020-04-18T11:00:18.150633+07:00",
subtotal: "370000.00",
},
],
})
)
.once(
JSON.stringify({
id: "663392ac-1dd6-462b-9301-a19c1287cefd",
username: "dummyuser",
full_name: "Dummy User",
phone_number: "+6285212345678",
address: "Jl. Dummy No.1",
neighborhood: "000",
hamlet: "000",
urban_village: "Dummy Urban Village",
sub_district: "Dummy Sub-District",
profile_picture: null,
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<DetailPengguna />
......@@ -41,14 +88,61 @@ test("Test detail pengguna renders", async () => {
});
test("Test mock return error", async () => {
fetch.mockReject(new Error("fake error message"));
fetch
.once(
JSON.stringify({
count: 17,
next:
"https://industripilar-staging.herokuapp.com/transactions/?page=2",
previous: null,
results: [
{
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",
shipping_sub_district: "Dummy Sub-District",
transaction_items: [
{
id: "37f0298c-2e8a-4ab0-a094-e9177ddc60c4",
product: "3d403cd3-e356-4c15-9a86-8843333e2778",
product_code: "5VK6TY",
product_name: "produk barang",
product_price: "50000.00",
quantity: 7,
},
],
transaction_item_subtotal: "350000.00",
shipping_costs: "15000.00",
payment_method: "TRF",
readable_payment_method: "Transfer",
donation: "5000.00",
transaction_status: "002",
readable_transaction_status: "Waiting for seller confirmation",
proof_of_payment: null,
user_bank_account_name: "test",
user_bank_account_number: "1232131241321",
created_at: "2020-04-18T10:59:42.074386+07:00",
updated_at: "2020-04-18T11:00:18.150633+07:00",
subtotal: "370000.00",
},
],
})
)
.mockReject(new Error("fake error message"));
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<DetailPengguna />
</AuthContext.Provider>
);
const page = getByTestId("page");
const page = getByTestId("page-profile");
await waitFor(() =>
expect(page.textContent).toContain("Error !, Please relogin..")
);
......
......@@ -70,8 +70,7 @@ test("Test edit produk renders error", async () => {
{
id: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
name: "Baju",
image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/categories/download.png",
image: null,
},
{
id: "0664247c-d9ea-4e56-bb02-4b8463f9e14c",
......@@ -134,6 +133,8 @@ test("Test edit produk renders error", async () => {
await fireEvent.submit(getByTestId("submit-produk"));
});
const produk = getByTestId("edit-produk");
expect(produk.textContent).toContain("Error loading form !, Please relogin");
expect(produk.textContent).toContain(
"Error loading form !, Please relogin.."
);
expect(fetch.mock.calls.length).toEqual(5);
});
import { cleanup, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import ListSubkategori from "../../page/produk/ListProduk";
import { waitFor } from "@testing-library/dom";
import ListProduk from "../../page/produk/ListProduk";
beforeEach(() => {
fetch.resetMocks();
......@@ -12,32 +12,46 @@ afterEach(cleanup);
test(" Test List produk", async () => {
fetch.mockResponseOnce(
JSON.stringify({
count: 2,
next: null,
count: 23,
next: "https://industripilar-staging.herokuapp.com/products/?page=2",
previous: null,
results: [
{
id: "1fac049f-592c-4c15-afe6-9e05a2ce1540",
name: "Kue Nastar",
price: 10000,
stock: 10,
id: "3d403cd3-e356-4c15-9a86-8843333e2778",
code: "5VK6TY",
name: "a",
category: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
category_name: "Baju",
subcategory: "626aa022-50a7-4d3a-b658-79cb0f059b03",
subcategory_name: "Baju Tidur hehe",
description: "celana",
price: "50000.00",
stock: 9,
image: null,
},
{
id: "626aa022-50a7-4d3a-b658-79cb0f059b03",
name: "Kastangel",
price: 40000,
stock: 4,
id: "9a0bccaa-70f6-48a8-89fc-5c5994684729",
code: "4QKSBC",
name: "Piyama",
category: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
category_name: "Baju",
subcategory: "626aa022-50a7-4d3a-b658-79cb0f059b03",
subcategory_name: "Baju Tidur hehe",
description: "piyama",
price: "50000.00",
stock: 14,
image: null,
},
],
})
);
const { getByTestId, getByText } = render(
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListSubkategori />
<ListProduk />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
const data = getByText("Kue Nastar");
expect(data.textContent).toContain("Kue Nastar");
const data = getByTestId("tableList");
expect(data.textContent).toContain("Piyama");
expect(fetch.mock.calls.length).toEqual(1);
});
......@@ -18,8 +18,7 @@ test("Test tambah produk renders", async () => {
{
id: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
name: "Baju",
image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/categories/download.png",
image: null,
},
{
id: "0664247c-d9ea-4e56-bb02-4b8463f9e14c",
......@@ -102,8 +101,7 @@ test("Test tambah produk form required", async () => {
{
id: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
name: "Baju",
image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/categories/download.png",
image: null,
},
{
id: "0664247c-d9ea-4e56-bb02-4b8463f9e14c",
......@@ -172,8 +170,7 @@ test("Test tambah produk error", async () => {
{
id: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
name: "Baju",
image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/categories/download.png",
image: null,
},
{
id: "0664247c-d9ea-4e56-bb02-4b8463f9e14c",
......@@ -223,14 +220,28 @@ test("Test tambah produk error", async () => {
<TambahProduk />
</AuthContext.Provider>
);
const name_produk = getByTestId("name-produk-input");
await act(async () => {
await fireEvent.input(name_produk, { target: { value: "test" } });
});
const desc_produk = getByTestId("desc-produk-input");
await act(async () => {
await fireEvent.input(desc_produk, { target: { value: "test" } });
});
const price_produk = getByTestId("price-produk-input");
await act(async () => {
await fireEvent.input(price_produk, { target: { value: "1" } });
});
const stock_produk = getByTestId("stock-produk-input");
await act(async () => {
await fireEvent.input(stock_produk, { target: { value: "-1" } });
await fireEvent.input(stock_produk, { target: { value: "1" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-produk"));
});
const produk = getByTestId("tambah-produk");
expect(produk.textContent).toContain("Error loading form !, Please relogin");
expect(fetch.mock.calls.length).toEqual(3);
expect(produk.textContent).toContain(
"Error loading form !, Please relogin.."
);
expect(fetch.mock.calls.length).toEqual(4);
});
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import DetailTransaksi from "../../page/transaksi/DetailTransaksi";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test detail loaded TRANSFER", async () => {
fetch.mockResponseOnce(
JSON.stringify({
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",
shipping_sub_district: "Dummy Sub-District",
transaction_items: [
{
id: "37f0298c-2e8a-4ab0-a094-e9177ddc60c4",
product: "3d403cd3-e356-4c15-9a86-8843333e2778",
product_code: "5VK6TY",
product_name: "produk barang",
product_price: "50000.00",
quantity: 7,
},
],
transaction_item_subtotal: "350000.00",
shipping_costs: "15000.00",
payment_method: "TRF",
readable_payment_method: "Transfer",
donation: "5000.00",
transaction_status: "002",
readable_transaction_status: "Waiting for seller confirmation",
proof_of_payment: "a",
user_bank_account_name: "test",
user_bank_account_number: "1232131241321",
created_at: "2020-04-18T10:59:42.074386+07:00",
updated_at: "2020-04-18T11:00:18.150633+07:00",
subtotal: "370000.00",
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailTransaksi idTransaksi={"0c1db3b2-48f0-4604-83ca-e8f16e8550ab"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-transaksi");
expect(wait.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("page-detail-transaksi"));
const data = getByTestId("page-detail-transaksi");
expect(data.textContent).toContain("Transfer");
await act(async () => {
await fireEvent.click(getByTestId("button-see-proof"));
});
const close = getByTestId("button-close-proof");
expect(close.textContent).toContain("Close");
await act(async () => {
await fireEvent.click(close);
});
const dropdown = getByTestId("dropdown-status");
expect(dropdown.children.length).toEqual(6);
});
test("Test detail loaded COD", async () => {
fetch.mockResponseOnce(
JSON.stringify({
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",
shipping_sub_district: "Dummy Sub-District",
transaction_items: [
{
id: "37f0298c-2e8a-4ab0-a094-e9177ddc60c4",
product: "3d403cd3-e356-4c15-9a86-8843333e2778",
product_code: "5VK6TY",
product_name: "produk barang",
product_price: "50000.00",
quantity: 7,
},
],
transaction_item_subtotal: "350000.00",
shipping_costs: "15000.00",
payment_method: "COD",
readable_payment_method: "Pembayaran di tempat",
donation: "5000.00",
transaction_status: "002",
readable_transaction_status: "Waiting for seller confirmation",
proof_of_payment: "a",
user_bank_account_name: "test",
user_bank_account_number: "1232131241321",
created_at: "2020-04-18T10:59:42.074386+07:00",
updated_at: "2020-04-18T11:00:18.150633+07:00",
subtotal: "370000.00",
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailTransaksi idTransaksi={"0c1db3b2-48f0-4604-83ca-e8f16e8550ab"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-transaksi");
expect(wait.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("page-detail-transaksi"));
const data = getByTestId("page-detail-transaksi");
expect(data.textContent).toContain("Cash On Delivery");
const dropdown = getByTestId("dropdown-status");
expect(dropdown.children.length).toEqual(5);
});
test("Test detail loaded error", async () => {
fetch.mockResponseOnce(JSON.stringify({}), { status: 400 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailTransaksi idTransaksi={"0c1db3b2-48f0-4604-83ca-e8f16e8550ab"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-transaksi");
await waitFor(() => wait);
expect(wait.textContent).toContain("Something error");
});
test("Test detail loaded submit", async () => {
fetch
.once(
JSON.stringify({
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",
shipping_sub_district: "Dummy Sub-District",
transaction_items: [
{
id: "37f0298c-2e8a-4ab0-a094-e9177ddc60c4",
product: "3d403cd3-e356-4c15-9a86-8843333e2778",
product_code: "5VK6TY",
product_name: "produk barang",
product_price: "50000.00",
quantity: 7,
},
],
transaction_item_subtotal: "350000.00",
shipping_costs: "15000.00",
payment_method: "TRF",
readable_payment_method: "Transfer",
donation: "5000.00",
transaction_status: "002",
readable_transaction_status: "Waiting for seller confirmation",
proof_of_payment: "a",
user_bank_account_name: "test",
user_bank_account_number: "1232131241321",
created_at: "2020-04-18T10:59:42.074386+07:00",
updated_at: "2020-04-18T11:00:18.150633+07:00",
subtotal: "370000.00",
})
)
.once(JSON.stringify({}), { statusCode: 204 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailTransaksi idTransaksi={"0c1db3b2-48f0-4604-83ca-e8f16e8550ab"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-transaksi");
expect(wait.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("page-detail-transaksi"));
const data = getByTestId("page-detail-transaksi");
expect(data.textContent).toContain("Transfer");
const dropdown = getByTestId("dropdown-status");
expect(dropdown.children.length).toEqual(6);
await act(async () => {
await fireEvent.click(getByTestId("button-submit-status"));
});
expect(fetch.mock.calls.length).toEqual(2);
});
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import ListTransaksi from "../../page/transaksi/ListTransaksi";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test(" Test List transaksi", async () => {
fetch.mockResponseOnce(
JSON.stringify({
count: 17,
next: "https://industripilar-staging.herokuapp.com/transactions/?page=2",
previous: null,
results: [
{
id: "0c1db3b2-48f0-4604-83ca-e8f16e8550ab",
transaction_number: "H793P5ZK",
user: "d4b98bb5-8ba4-4a41-af10-93abcf53df58",
user_username: "whtestest",
user_full_name: "Michael Wiryadinata halim",
user_phone_number: "+628192090199",
shipping_address: "ada deh test",
shipping_neighborhood: "002",
shipping_hamlet: "002",
shipping_urban_village: "penggilingan",