Tests refactor
This commit is contained in:
parent
245520fb50
commit
99134d8556
165 changed files with 911 additions and 531 deletions
19
packages/api/tests/schemas/household.schema.test.ts
Normal file
19
packages/api/tests/schemas/household.schema.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { HouseholdModel } from '../../src/schemas/household.schema.js';
|
||||
|
||||
describe('HouseholdModel', () => {
|
||||
it('is a valid mongoose model', () => {
|
||||
expect(HouseholdModel.modelName).toBe('Household');
|
||||
});
|
||||
|
||||
it('has expected schema paths', () => {
|
||||
const paths = Object.keys(HouseholdModel.schema.paths);
|
||||
expect(paths).toContain('name');
|
||||
expect(paths).toContain('ownerUserId');
|
||||
expect(paths).toContain('members');
|
||||
expect(paths).toContain('inviteCode');
|
||||
expect(paths).toContain('settings');
|
||||
expect(paths).toContain('createdAt');
|
||||
expect(paths).toContain('updatedAt');
|
||||
});
|
||||
});
|
||||
23
packages/api/tests/schemas/medicine-product.schema.test.ts
Normal file
23
packages/api/tests/schemas/medicine-product.schema.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { MedicineProductModel } from '../../src/schemas/medicine-product.schema.js';
|
||||
|
||||
describe(MedicineProductModel.name, () => {
|
||||
it('is a valid mongoose model', () => {
|
||||
expect(MedicineProductModel.modelName).toBe('MedicineProduct');
|
||||
});
|
||||
|
||||
it('has expected schema paths', () => {
|
||||
const paths = Object.keys(MedicineProductModel.schema.paths);
|
||||
expect(paths).toContain('householdId');
|
||||
expect(paths).toContain('medicineId');
|
||||
expect(paths).toContain('medicineName');
|
||||
expect(paths).toContain('brand');
|
||||
expect(paths).toContain('packageSize');
|
||||
expect(paths).toContain('packageUnit');
|
||||
expect(paths).toContain('source');
|
||||
expect(paths).toContain('createdBy');
|
||||
expect(paths).toContain('isDeleted');
|
||||
expect(paths).toContain('createdAt');
|
||||
expect(paths).toContain('updatedAt');
|
||||
});
|
||||
});
|
||||
23
packages/api/tests/schemas/medicine.schema.test.ts
Normal file
23
packages/api/tests/schemas/medicine.schema.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { MedicineModel } from '../../src/schemas/medicine.schema.js';
|
||||
|
||||
describe(MedicineModel.name, () => {
|
||||
it('is a valid mongoose model', () => {
|
||||
expect(MedicineModel.modelName).toBe('Medicine');
|
||||
});
|
||||
|
||||
it('has expected schema paths', () => {
|
||||
const paths = Object.keys(MedicineModel.schema.paths);
|
||||
expect(paths).toContain('householdId');
|
||||
expect(paths).toContain('name');
|
||||
expect(paths).toContain('form');
|
||||
expect(paths).toContain('strength');
|
||||
expect(paths).toContain('strengthUnit');
|
||||
expect(paths).toContain('category');
|
||||
expect(paths).toContain('tags');
|
||||
expect(paths).toContain('createdBy');
|
||||
expect(paths).toContain('isDeleted');
|
||||
expect(paths).toContain('createdAt');
|
||||
expect(paths).toContain('updatedAt');
|
||||
});
|
||||
});
|
||||
32
packages/api/tests/schemas/product.schema.test.ts
Normal file
32
packages/api/tests/schemas/product.schema.test.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { ProductModel } from '../../src/schemas/product.schema.js';
|
||||
|
||||
describe(ProductModel.name, () => {
|
||||
it('is a valid mongoose model', () => {
|
||||
expect(ProductModel.modelName).toBe('Product');
|
||||
});
|
||||
|
||||
it('has expected schema paths', () => {
|
||||
const paths = Object.keys(ProductModel.schema.paths);
|
||||
expect(paths).toContain('householdId');
|
||||
expect(paths).toContain('name');
|
||||
expect(paths).toContain('category');
|
||||
expect(paths).toContain('servingSize');
|
||||
expect(paths).toContain('servingUnit');
|
||||
expect(paths).toContain('nutrition');
|
||||
expect(paths).toContain('tags');
|
||||
expect(paths).toContain('source');
|
||||
expect(paths).toContain('createdBy');
|
||||
expect(paths).toContain('deletedAt');
|
||||
expect(paths).toContain('createdAt');
|
||||
expect(paths).toContain('updatedAt');
|
||||
});
|
||||
|
||||
it('has expected indexes defined', () => {
|
||||
const indexes = ProductModel.schema.indexes();
|
||||
const indexKeys = indexes.map(([key]) => Object.keys(key).join(','));
|
||||
expect(indexKeys).toContain('householdId,name,brand,tags');
|
||||
expect(indexKeys).toContain('householdId,deletedAt,category');
|
||||
expect(indexKeys).toContain('householdId,barcode');
|
||||
});
|
||||
});
|
||||
19
packages/api/tests/schemas/user.schema.test.ts
Normal file
19
packages/api/tests/schemas/user.schema.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { UserModel } from '../../src/schemas/user.schema.js';
|
||||
|
||||
describe('UserModel', () => {
|
||||
it('is a valid mongoose model', () => {
|
||||
expect(UserModel.modelName).toBe('User');
|
||||
});
|
||||
|
||||
it('has expected schema paths', () => {
|
||||
const paths = Object.keys(UserModel.schema.paths);
|
||||
expect(paths).toContain('keycloakId');
|
||||
expect(paths).toContain('displayName');
|
||||
expect(paths).toContain('email');
|
||||
expect(paths).toContain('householdIds');
|
||||
expect(paths).toContain('defaultHouseholdId');
|
||||
expect(paths).toContain('createdAt');
|
||||
expect(paths).toContain('updatedAt');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue