Skip to content

Commit

Permalink
Merge pull request #252 from Arquisoft/pablof
Browse files Browse the repository at this point in the history
Hot Fix Arreglo test
  • Loading branch information
uo277931 authored May 3, 2022
2 parents 3917d98 + 4c333d9 commit 27971a9
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 15 deletions.
8 changes: 8 additions & 0 deletions docs/05_building_block_view.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ Contained Building Blocks::
|Name| Description
|Webapp | Part of the application that the user will see and interact with.
|Restapi | Part of the application responsible for persistence.
|Register | Part of the application responsible for creating new users.
|Login | Part of the application responsible for user access.
|Orders | Part of the application responsible for order management.
|Cart | Part of the application responsible for storing the products that the user wants to buy.
|Products | Part of the application responsible for products management.
|Cloudinary | External service responsible for storing the images of the application.
|Shippo | External service responsible for providing the shipping cost.
|Nodemailer | External service responsible for sending emails.
|===
3 changes: 2 additions & 1 deletion webapp/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default {
"\\.[jt]sx?$": "babel-jest",
"^.+\\.tsx?$": "ts-jest",
},
collectCoverage: true
collectCoverage: true,
setupFiles: ['<rootDir>/vars.ts']
}
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --coverage",
"test:e2e": "start-server-and-test 'npm --prefix ../restapi start' http://localhost:5000/api/product/list prod 3000 'cd e2e && jest'",
"eject": "react-scripts eject",
"prod": "ts-node-dev ./server.ts"
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/components/Cart/Address.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render } from "@testing-library/react";
import { BrowserRouter} from 'react-router-dom';
import Address from "./Address";

test('check the address form render properly', async () => {
const {getByText} = render(<BrowserRouter><Address/></BrowserRouter>);
expect(getByText("Your address")).toBeInTheDocument();
});
8 changes: 8 additions & 0 deletions webapp/src/components/Cart/Payment.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render } from "@testing-library/react";
import { BrowserRouter} from 'react-router-dom';
import Payment from "./Payment";

test('check the payment form render properly', async () => {
const {getByText} = render(<BrowserRouter><Payment/></BrowserRouter>);
expect(getByText("Payment")).toBeInTheDocument();
});
29 changes: 29 additions & 0 deletions webapp/src/components/Order/Order.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render } from "@testing-library/react";
import { BrowserRouter } from 'react-router-dom';
import Order from "./Order";
import * as api from '../Services/OrderService'
import { Item, OrderType, Producto, User } from "../../shared/sharedtypes";
import { ReactSession } from 'react-client-session';

jest.mock('../Services/OrderService');

test('check the payment form render properly', async () => {
const user: User = {
username: process.env.USER2!,
password: process.env.USER2!,
token: ""
};
const product: Producto = { category: 'cellular', name: 'IPhone', description: 'a', urlImage: 'aaaaa', basePrice: 200, units: 2, onSale: true, IVA: 0.21 };
const listProd: Item[] = [{ producto: product, num: 3 }];
const order: OrderType = {
_id: '', user: user,
products: listProd,
totalPrice: 0
};
ReactSession.set("user", user);
jest.spyOn(api, 'getOrder').mockImplementation((id: String, token: string): Promise<OrderType> => Promise.resolve(order));

const { getByText, container } = render(<BrowserRouter><Order /></BrowserRouter>);
expect(getByText("Order")).toBeInTheDocument();

});
19 changes: 10 additions & 9 deletions webapp/src/components/Order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ const Order = () => {
const params = useParams();

const loadOrder = async () => {
let user = ReactSession.get("user");
let res = await orderService.getOrder(params._id as string,user.token);
if(res.data.order){
setOrder(res.data.order)
let user = ReactSession.get("user");
let ord = await orderService.getOrder(params._id as string,user.token);
setOrder(ord);
let prods:Product[] = [];
for(var p in res.data.order.products){
var product = {name:p,num:res.data.order.products[p]};
prods.push(product);
if(order != undefined){
for(var p in order!.products){
var product = {name:p,num:order!.products[p].num};
prods.push(product);
}
setProductos(prods);
}
setProductos(prods);
}
}

const download = () => {
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/Order/Orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ const Orders = () => {
const [orders, setOrders] = useState<OrderType[]>([]);

const loadOrders = async () => {
let res = await orderService.getOrdersOf(ReactSession.get("user"));
setOrders(res.data.orders);
let res = await orderService.getOrdersOf(ReactSession.get("user"));
setOrders(res.data.orders);
}

useEffect(() => {
loadOrders();
}, [])


return (
<div>
<h1 className='title'>My orders</h1>
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/Services/OrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const getOrdersOf = async (u: User) => {
};

export const getOrder = async (id: string, token:string) => {
return await axios.get(`${API}/order/`+id, {headers:{'Authorization': token}});
let res = await axios.get(`${API}/order/`+id, {headers:{'Authorization': token}});
return res.data.order;
};

export const getShippingDetails = async (user:string, address: AddressType, token:string) => {
Expand Down
4 changes: 3 additions & 1 deletion webapp/vars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
process.env.USER = 'pruebaprueba'
process.env.PASS = 'PruebaPrueba1+'
process.env.BADUSER = 'pru'
process.env.BADPASS = 'Prueb'
process.env.BADPASS = 'Prueb'
process.env.USER2= 'user'
process.env.PASS2= 'user'

0 comments on commit 27971a9

Please sign in to comment.