tests: add tests for RecipesService

WORK-RRE
Rémi REGNAULT 1 year ago
parent a761314e58
commit f124ea3d3e

@ -1,19 +1,19 @@
import Profil from "../../Models/Profil"; import Profile from "../../Models/Profile";
import IProfileService from "./IProfileService"; import IProfileService from "./IProfileService";
import AsyncStorage from "@react-native-async-storage/async-storage"; import AsyncStorage from "@react-native-async-storage/async-storage";
export default class ProfileService implements IProfileService { export default class ProfileService implements IProfileService {
async getProfiles(): Promise<Profil[]> { async getProfiles(): Promise<Profile[]> {
const results = await AsyncStorage.getItem('profiles'); const results = await AsyncStorage.getItem('profiles');
const tmp = JSON.parse(results) const tmp = JSON.parse(results)
let existingProfiles: Profil[] = [] let existingProfiles: Profile[] = []
for (let item of tmp) { for (let item of tmp) {
existingProfiles.push(new Profil(item._name, item._avatar, item._allergy, item._diets)) existingProfiles.push(new Profile(item._name, item._avatar, item._allergy, item._diets))
} }
return existingProfiles; return existingProfiles;
} }
async addProfile(new_profile : Profil): Promise<boolean> { async addProfile(new_profile : Profile): Promise<boolean> {
const existingProfiles = await this.getProfiles() const existingProfiles = await this.getProfiles()
for (let current_profile of existingProfiles) { for (let current_profile of existingProfiles) {
if (current_profile.name == new_profile.name) { if (current_profile.name == new_profile.name) {

@ -29,7 +29,7 @@ describe('IngredientService', () => {
const result = await ingredient_service.getfilteredIngredient('car') const result = await ingredient_service.getfilteredIngredient('car')
let test = true let test = true
for (let ingredient of result) { for (let ingredient of result) {
if (ingredient.name.includes('car')) { if (!ingredient.name.includes('car')) {
test = false test = false
} }
} }

@ -0,0 +1,22 @@
import RecipesService from '../Services/Recipes/RecipesServices';
describe('RecipesService', () => {
const recipe_service = new RecipesService();
it('should get one recipe', async () => {
const result = await recipe_service.getRecipeById(4444)
expect(result.id).toBe(4444);
});
it('should get all recipes', async () => {
const result = await recipe_service.getAllRecipes()
const test = result.length >= 1
expect(test).toBe(true);
}, 120000);
it('should get one recipe', async () => {
const result = await recipe_service.getRecipeWithIngredients(['1928:2148:2809:2853:3723:6261:6335:7076'])
const test = result.length >= 1
expect(test).toBe(true);
});
});
Loading…
Cancel
Save