-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(all): filter cocktails by ingredient show handle replacementIds (#…
…202)
- Loading branch information
1 parent
efaa05b
commit 48ef3f7
Showing
13 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
• Fixed filter Cocktails by Ingredient to include substitute ingredients | ||
• Fixed issue with showing mocktails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Ingredient } from 'domain/entities/ingredient'; | ||
|
||
export class IngredientMapper { | ||
static toIngredientAndReplacementIds(ingredient: Ingredient) { | ||
let ids: string[] = [ingredient.id]; | ||
|
||
if (ingredient.replacementIds !== undefined) { | ||
ids.push(...ingredient.replacementIds); | ||
} | ||
return ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'reflect-metadata'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getStaticIngredients } from 'data/ingredient-data'; | ||
import { Ingredient } from 'domain/entities/ingredient'; | ||
import { IngredientMapper } from 'domain/mappers/ingredient-mapper'; | ||
|
||
describe('IngredientMapper', () => { | ||
test('toIngredientAndReplacementIds - No replacementIds', () => { | ||
let ingredient = getStaticIngredients()[0] as Ingredient; | ||
|
||
let result = IngredientMapper.toIngredientAndReplacementIds(ingredient); | ||
|
||
expect(result).toStrictEqual(['1']); | ||
}); | ||
|
||
test('toIngredientAndReplacementIds - With replacementIds', () => { | ||
let ingredient = getStaticIngredients()[18] as Ingredient; | ||
|
||
let result = IngredientMapper.toIngredientAndReplacementIds(ingredient); | ||
|
||
expect(result).toStrictEqual(['19', '38', '92']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { IngredientService } from 'services/ingredient-service'; | ||
import { LocalStorageService } from 'services/local-storage-service'; | ||
import { I18N } from 'aurelia-i18n'; | ||
|
||
describe('IngredientService', () => { | ||
let localStorageService: LocalStorageService; | ||
let sut: IngredientService; | ||
|
||
beforeEach(async () => { | ||
localStorageService = new LocalStorageService(); | ||
await localStorageService.initialize(); | ||
|
||
let i18n = new I18N(null, null); | ||
jest.spyOn(i18n, 'tr').mockReturnValue('name'); | ||
sut = new IngredientService(localStorageService, i18n); | ||
}); | ||
|
||
afterEach(() => { | ||
window.localStorage.clear(); | ||
}); | ||
|
||
describe('GET', () => { | ||
test('Get Ingredients - No initial state', () => { | ||
expect(sut.getIngredients().length).toBeGreaterThan(0); | ||
expect(sut.getCreatedIngredients()).toHaveLength(0); | ||
}); | ||
|
||
test('Get Random Ingredients', () => { | ||
expect(sut.getRandomIngredients(0)).toHaveLength(0); | ||
expect(sut.getRandomIngredients(3)).toHaveLength(3); | ||
}); | ||
|
||
test('getIngredientAndReplacementIds - Ingredient not found', () => { | ||
expect(sut.getIngredientAndReplacementIds('error')).toStrictEqual([]); | ||
}); | ||
}); | ||
|
||
describe('Create', () => { | ||
test('Create Ingredient', async () => { | ||
let key = 'CapacitorStorage.ingredients'; | ||
expect(window.localStorage.getItem(key)).toBeNull(); | ||
|
||
let ingredient = await sut.createIngredient('Test'); | ||
expect(ingredient.id).toBe('x-1'); | ||
|
||
expect(window.localStorage.getItem(key)).toBeTruthy(); | ||
expect(sut.getCreatedIngredients()).toStrictEqual([ingredient]); | ||
expect(sut.getIngredients()).toContain(ingredient); | ||
}); | ||
}); | ||
|
||
describe('Update', () => { | ||
test('Update Ingredient', async () => { | ||
let ingredient = await sut.createIngredient('Test'); | ||
|
||
let updatedIngredient = { ...ingredient }; | ||
updatedIngredient.name = 'updated'; | ||
|
||
await sut.updateIngredient(updatedIngredient); | ||
|
||
expect(ingredient.id).toBe('x-1'); | ||
expect(sut.getCreatedIngredients()).toStrictEqual([updatedIngredient]); | ||
expect(sut.getIngredients()).toContain(updatedIngredient); | ||
}); | ||
}); | ||
|
||
describe('Delete', () => { | ||
test('Delete Ingredient', async () => { | ||
let ingredient = await sut.createIngredient('Test'); | ||
|
||
await sut.deleteIngredient(ingredient.id); | ||
|
||
expect(sut.getCreatedIngredients()).toStrictEqual([]); | ||
expect(sut.getIngredientById(ingredient.id)).toBeUndefined(); | ||
}); | ||
}); | ||
}); |