Make testOfferPermissions more reliable

The order of the permissions is undefined and will vary based on what order
things happen to resolve on the server.
This commit is contained in:
Thomas Goyne 2018-03-02 12:13:59 -08:00
parent 5ff5df97be
commit 384f43c637

View File

@ -85,18 +85,31 @@ function waitForUpload(realm) {
}); });
} }
function permissionForPath(permissions, path) {
for (const permission of permissions) {
if (permission.path == path) {
return permission;
}
}
}
module.exports = { module.exports = {
testApplyAndGetGrantedPermissions() { testApplyAndGetGrantedPermissions() {
return createUsersWithTestRealms(1) return createUsersWithTestRealms(1)
.then(([user]) => { .then(([user]) => {
const path = `/${user.identity}/test`;
return user.applyPermissions({userId: `${user.identity}`}, `/${user.identity}/test`, 'read') return user.applyPermissions({userId: `${user.identity}`}, `/${user.identity}/test`, 'read')
.then(repeatUntil(() => user.getGrantedPermissions('any'), .then(repeatUntil(() => user.getGrantedPermissions('any'),
permissions => permissions.length > 1)) permissions => {
let permission = permissionForPath(permissions, path);
return permission && !permission.mayWrite;
}))
.then(permissions => { .then(permissions => {
TestCase.assertEqual(permissions[0].path, `/${user.identity}/test`); let permission = permissionForPath(permissions, path);
TestCase.assertEqual(permissions[0].mayRead, true); TestCase.assertDefined(permission);
TestCase.assertEqual(permissions[0].mayWrite, false); TestCase.assertEqual(permission.mayRead, true);
TestCase.assertEqual(permissions[0].mayManage, false); TestCase.assertEqual(permission.mayWrite, false);
TestCase.assertEqual(permission.mayManage, false);
}); });
}); });
}, },
@ -104,19 +117,21 @@ module.exports = {
testOfferPermissions() { testOfferPermissions() {
return createUsersWithTestRealms(2) return createUsersWithTestRealms(2)
.then(([user1, user2]) => { .then(([user1, user2]) => {
const path = `/${user1.identity}/test`;
return user1.offerPermissions(`/${user1.identity}/test`, 'read') return user1.offerPermissions(`/${user1.identity}/test`, 'read')
.then(token => user2.acceptPermissionOffer(token)) .then(token => user2.acceptPermissionOffer(token))
.then(realmUrl => { .then(realmUrl => {
TestCase.assertEqual(realmUrl, `/${user1.identity}/test`); TestCase.assertEqual(realmUrl, path);
return realmUrl; return realmUrl;
}) })
.then(repeatUntil(() => user2.getGrantedPermissions('any'), .then(repeatUntil(() => user2.getGrantedPermissions('any'),
permissions => permissions.length > 1)) permissions => permissions.length > 2 && permissionForPath(permissions, path)))
.then(permissions => { .then(permissions => {
TestCase.assertEqual(permissions[2].path, `/${user1.identity}/test`); let permission = permissionForPath(permissions, path)
TestCase.assertEqual(permissions[2].mayRead, true); TestCase.assertDefined(permission);
TestCase.assertEqual(permissions[2].mayWrite, false); TestCase.assertEqual(permission.mayRead, true);
TestCase.assertEqual(permissions[2].mayManage, false); TestCase.assertEqual(permission.mayWrite, false);
TestCase.assertEqual(permission.mayManage, false);
}); });
}); });
}, },