Skip to content

Commit 1ca66a3

Browse files
author
Alejandro Caicedo
committed
feat: add product type to product mutations and queries, update user termsAccepted field
1 parent 1f1a0c8 commit 1ca66a3

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

__tests__/modules/products/application/product.mutations.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ describe('product.mutations', () => {
5656

5757
describe('useProductCreate', () => {
5858
it('should create product and invalidate queries on success', async () => {
59-
const mockProduct = { id: '1', name: 'New Product', description: 'Desc', price: 100, createdAt: new Date(), updatedAt: new Date() };
59+
const mockProduct = { id: '1', name: 'New Product', description: 'Desc', price: 100, type: 'comida' as const, createdAt: new Date(), updatedAt: new Date() };
6060
mockProductService.create.mockResolvedValue(mockProduct);
6161

6262
const { mutate } = useProductCreate();
63-
await mutate({ name: 'New Product', description: 'Desc', price: 100 });
63+
await mutate({ name: 'New Product', description: 'Desc', price: 100, type: { label: 'Comida', value: 'comida' } });
6464

6565
expect(mockProductService.create).toHaveBeenCalled();
6666
expect(mockInvalidateQueries).toHaveBeenCalledWith({
@@ -69,11 +69,11 @@ describe('product.mutations', () => {
6969
});
7070

7171
it('should show success toast on create', async () => {
72-
const mockProduct = { id: '1', name: 'New Product', description: 'Desc', price: 100, createdAt: new Date(), updatedAt: new Date() };
72+
const mockProduct = { id: '1', name: 'New Product', description: 'Desc', price: 100, type: 'comida' as const, createdAt: new Date(), updatedAt: new Date() };
7373
mockProductService.create.mockResolvedValue(mockProduct);
7474

7575
const { mutate } = useProductCreate();
76-
await mutate({ name: 'New Product', description: 'Desc', price: 100 });
76+
await mutate({ name: 'New Product', description: 'Desc', price: 100, type: { label: 'Comida', value: 'comida' } });
7777

7878
// Toast is called via useAppStorage mock
7979
});
@@ -85,17 +85,17 @@ describe('product.mutations', () => {
8585
const { mutate } = useProductCreate();
8686

8787
// The mutation will throw because the service returns an Error
88-
await expect(mutate({ name: 'Test', description: 'Desc', price: 100 })).rejects.toThrow();
88+
await expect(mutate({ name: 'Test', description: 'Desc', price: 100, type: { label: 'Comida', value: 'comida' } })).rejects.toThrow();
8989
});
9090
});
9191

9292
describe('useProductUpdate', () => {
9393
it('should update product and invalidate queries on success', async () => {
94-
const mockProduct = { id: '1', name: 'Updated Product', description: 'Desc', price: 200, createdAt: new Date(), updatedAt: new Date() };
94+
const mockProduct = { id: '1', name: 'Updated Product', description: 'Desc', price: 200, type: 'comida' as const, createdAt: new Date(), updatedAt: new Date() };
9595
mockProductService.update.mockResolvedValue(mockProduct);
9696

9797
const { mutate } = useProductUpdate();
98-
await mutate({ id: '1', form: { name: 'Updated Product', description: 'Desc', price: 200 } });
98+
await mutate({ id: '1', form: { name: 'Updated Product', description: 'Desc', price: 200, type: { label: 'Comida', value: 'comida' } } });
9999

100100
expect(mockProductService.update).toHaveBeenCalledWith('1', expect.any(Object));
101101
expect(mockInvalidateQueries).toHaveBeenCalledWith({
@@ -113,7 +113,7 @@ describe('product.mutations', () => {
113113
const { mutate } = useProductUpdate();
114114

115115
await expect(
116-
mutate({ id: '1', form: { name: 'Test', description: 'Desc', price: 100 } }),
116+
mutate({ id: '1', form: { name: 'Test', description: 'Desc', price: 100, type: { label: 'Comida', value: 'comida' } } }),
117117
).rejects.toThrow();
118118
});
119119
});

__tests__/modules/products/application/product.queries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('product.queries', () => {
5858
});
5959

6060
it('should call productService.getAll in queryFn', async () => {
61-
const mockProducts = [{ id: '1', name: 'Product 1', description: 'Desc', price: 100, createdAt: new Date(), updatedAt: new Date() }];
61+
const mockProducts = [{ id: '1', name: 'Product 1', description: 'Desc', price: 100, type: 'comida' as const, createdAt: new Date(), updatedAt: new Date() }];
6262
mockProductService.getAll.mockResolvedValue(mockProducts);
6363
mockUseQuery.mockImplementation(async ({ queryFn }) => {
6464
await queryFn();
@@ -114,7 +114,7 @@ describe('product.queries', () => {
114114
});
115115

116116
it('should call productService.getById in queryFn', async () => {
117-
const mockProduct = { id: '1', name: 'Product 1', description: 'Desc', price: 100, createdAt: new Date(), updatedAt: new Date() };
117+
const mockProduct = { id: '1', name: 'Product 1', description: 'Desc', price: 100, type: 'comida' as const, createdAt: new Date(), updatedAt: new Date() };
118118
mockProductService.getById.mockResolvedValue(mockProduct);
119119
mockUseQuery.mockImplementation(async ({ queryFn }) => {
120120
const data = await queryFn();

src/modules/products/infrastructure/product.firebase.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ProductFirebaseDoc {
1818
name: string;
1919
description: string;
2020
price: number;
21+
type: string;
2122
createdAt: Timestamp;
2223
updatedAt: Timestamp;
2324
}
@@ -29,6 +30,7 @@ interface ProductFirebaseEntity extends ProductFirebaseDoc {
2930
function toProduct(entity: ProductFirebaseEntity): Product {
3031
return {
3132
...entity,
33+
type: entity.type as Product['type'],
3234
createdAt: new Date(entity.createdAt.seconds * 1000),
3335
updatedAt: new Date(entity.updatedAt.seconds * 1000),
3436
};

src/modules/products/ui/components/ProductItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const ProductItem = React.memo(function ProductItem({
3434
<Text variant="caption" color="primary">
3535
${product.price.toFixed(2)}
3636
</Text>
37-
<Text variant="caption" color="muted">
37+
<Text variant="caption" color="textSecondary">
3838
{product.type}
3939
</Text>
4040
</View>

src/modules/users/infrastructure/user.firebase.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface UserFirebaseDoc {
2121
phone: string;
2222
role: string;
2323
avatar?: string;
24+
termsAccepted: boolean;
2425
createdAt: Timestamp;
2526
updatedAt: Timestamp;
2627
}
@@ -33,6 +34,7 @@ function toUser(entity: UserFirebaseEntity): User {
3334
return {
3435
...entity,
3536
avatar: entity.avatar ?? undefined,
37+
termsAccepted: entity.termsAccepted ?? false,
3638
createdAt: new Date(entity.createdAt.seconds * 1000),
3739
updatedAt: new Date(entity.updatedAt.seconds * 1000),
3840
};
@@ -144,6 +146,7 @@ class UserFirebaseService implements UserRepository {
144146
email: data.email,
145147
phone: data.phone,
146148
role: data.role,
149+
termsAccepted: data.termsAccepted,
147150
createdAt: Timestamp.fromDate(now),
148151
updatedAt: Timestamp.fromDate(now),
149152
},

0 commit comments

Comments
 (0)