Skip to content

Commit

Permalink
tweak before hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil committed Oct 2, 2023
1 parent 2fb4120 commit 3879faf
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions packages/models/test/tests/0-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const shouldNotHappenThenner = function (err) {
expect(false).true;
};

const getDevices = function () {
const boxes = [
senseBox({ name: 'sb1' }),
senseBox({ name: 'sb2' }),
senseBox({ name: 'sb3' })
];

return new Promise((resolve) => {
setTimeout(() => resolve(boxes), 200);
});
};

describe('User model', function () {
before(function () {
return connect(dbConnectionString({ db: 'userTest' }))
Expand Down Expand Up @@ -506,17 +518,23 @@ describe('User model', function () {
});

describe('Box management', function () {
const boxes = [senseBox({ name: 'sb1' }), senseBox({ name: 'sb2' }), senseBox({ name: 'sb3' })];
// const boxes = [senseBox({ name: 'sb1' }), senseBox({ name: 'sb2' }), senseBox({ name: 'sb3' })];
let userBoxes;
before(function () {
return User.findOne({ name: 'Valid Username 2' })
.then(function (user) {
return Promise.all(boxes.map(function (box) {
return user.addBox(box).then(function (newBox) {
return newBox;
});
}));
});
before(async function () {
const user = await User.findOne({ name: 'Valid Username 2' });

const devices = await getDevices();
for (const device of devices) {
await user.addBox(device);
}
// return User.findOne({ name: 'Valid Username 2' })
// .then(function (user) {
// return Promise.all(boxes.map(function (box) {
// return user.addBox(box).then(function (newBox) {
// return newBox;
// });
// }));
// });
});

it('should allow to get all boxes with all details of a user', function () {
Expand Down

0 comments on commit 3879faf

Please sign in to comment.