forked from b00tc4mp/isdi-parttime-202309
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some test spec and refactor code b00tc4mp#407
- Loading branch information
Showing
18 changed files
with
631 additions
and
118 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
48 changes: 48 additions & 0 deletions
48
staff/belen-ivars/project/api/logic/chekIngredient.spec.js
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,48 @@ | ||
import dotenv from 'dotenv' | ||
dotenv.config() | ||
|
||
import mongoose from 'mongoose' | ||
|
||
import { expect } from 'chai' | ||
import random from './helpers/random.js' | ||
import checkIngredient from './checkIngredient.js' | ||
import { errors } from 'com' | ||
import { User } from '../data/models.js' | ||
import { NotFoundError, SystemError } from 'com/errors.js' | ||
const { DuplicityError } = errors | ||
const { ObjectId } = mongoose.Types | ||
|
||
describe('checkIngredient', () => { | ||
before(async () => await mongoose.connect(process.env.TEST_MONGODB_URL)) | ||
beforeEach(async () => await User.deleteMany()) | ||
|
||
it('succeds on current user', async () => { | ||
|
||
const name = random.name() | ||
const email = random.email() | ||
const password = random.password() | ||
const user = await User.create({ name, email, password }) | ||
|
||
const ingredient = random.ingredientName().toLowerCase() | ||
|
||
try { | ||
await checkIngredient(user.id, ingredient) | ||
|
||
expect(true).to.be.true | ||
} catch (error) { | ||
|
||
expect(error).to.be.an.instanceOf(SystemError) | ||
expect(ingredient).to.exist | ||
} | ||
}) | ||
after(async () => await mongoose.disconnect()) | ||
}) | ||
// it('fails on non-existing user', async () => { | ||
// try { | ||
// await checkIngredient(new ObjectId().toString()) | ||
// throw new Error('should not reach this point') | ||
// } catch (error) { | ||
// expect(error).to.be.instanceOf(NotFoundError) | ||
// expect(error.message).to.equal('No user found') | ||
// } | ||
// }) |
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
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
Oops, something went wrong.