2022-11-22 13:43:21 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
|
|
|
describe('MdbApp lock()', () => {
|
2022-11-23 09:41:32 +00:00
|
|
|
it('should throw an error if the app is already locked', async() => {
|
|
|
|
const tx = await models.MdbApp.beginTransaction({});
|
|
|
|
let error;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2022-11-23 09:56:55 +00:00
|
|
|
const appName = 'bar';
|
2022-11-23 09:41:32 +00:00
|
|
|
const developerId = 9;
|
|
|
|
const ctx = {
|
|
|
|
req: {
|
|
|
|
accessToken: {userId: developerId},
|
|
|
|
__: () => {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = await models.MdbApp.lock(ctx, appName, options);
|
|
|
|
|
|
|
|
expect(result.locked).not.toBeNull();
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2022-11-22 13:43:21 +00:00
|
|
|
it(`should lock a mdb `, async() => {
|
|
|
|
const tx = await models.MdbApp.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2022-11-23 09:56:55 +00:00
|
|
|
const appName = 'foo';
|
2022-11-22 13:43:21 +00:00
|
|
|
const developerId = 9;
|
|
|
|
const ctx = {req: {accessToken: {userId: developerId}}};
|
|
|
|
|
|
|
|
const result = await models.MdbApp.lock(ctx, appName, options);
|
|
|
|
|
|
|
|
expect(result.locked).not.toBeNull();
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|