You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { Product, ProductStore } from '../../models/product'
|
|
|
|
const store = new ProductStore()
|
|
|
|
describe("Products store Model", () => {
|
|
it('should have an index method', () => {
|
|
expect(store.index).toBeDefined();
|
|
});
|
|
|
|
it('index menthod should return a list of products', async () => {
|
|
const result = await store.index();
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it('should have a create method', () => {
|
|
expect(store.index).toBeDefined;
|
|
});
|
|
|
|
it('should have a update method', () => {
|
|
expect(store.index).toBeDefined;
|
|
});
|
|
|
|
it('create method should add a product', async () => {
|
|
const result = await store.create({
|
|
name: '1984',
|
|
price: 5,
|
|
|
|
});
|
|
expect(result).toEqual({
|
|
id: 1,
|
|
name: '1984',
|
|
price: 5,
|
|
});
|
|
});
|
|
|
|
it('index method should return a list of products', async () => {
|
|
const result = await store.index();
|
|
expect(result).toEqual([{
|
|
id: 1,
|
|
name: '1984',
|
|
price: 5,
|
|
}]);
|
|
|
|
});
|
|
|
|
it('show method should return a product', async () => {
|
|
const result = await store.show(1);
|
|
expect(result).toEqual({
|
|
id: 1,
|
|
name: '1984',
|
|
price: 5,
|
|
});
|
|
|
|
});
|
|
|
|
it('delete method should remove the product', async () => {
|
|
store.delete(1);
|
|
const result = await store.index()
|
|
|
|
expect(result).toEqual([]);
|
|
});
|
|
});
|
|
|