Skip to content

Commit

Permalink
Merge pull request #5447 from owncloud/remove-delete-shares
Browse files Browse the repository at this point in the history
[full-ci][Tests-Only] Fix intermittent failure on user creation
  • Loading branch information
individual-it authored Jul 9, 2021
2 parents 155481d + 01aba2f commit 567747b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Feature: restrict Sharing
| Alice |
| Brian |
| Carol |
And these users have been created without initialization and without skeleton files:
| username | password | displayname | email |
| Alison | %regular% | Alison Cooper | alson@oc.com.np |
And these users have been created with initialization and without skeleton files:
| username | password | displayname | email |
| Alison | %regular% | Alison Cooper | alson@oc.com.np |
And these groups have been created:
| groupname |
| grp1 |
Expand Down
13 changes: 2 additions & 11 deletions tests/acceptance/helpers/httpHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ const checkOCSStatus = function(response, message = '') {
}
}

/**
*
* @param {string} url
* @param {object} options
*
* @returns {node-fetch}
*/
const fetcher = (url, options) => fetch(url, options)

/**
*
* @param {string} path
Expand All @@ -87,7 +78,7 @@ const requestEndpoint = function(path, params, userId = 'admin', header = {}) {
const headers = { ...createAuthHeader(userId), ...header }
const options = { ...params, headers }
const url = join(backendHelper.getCurrentBackendUrl(), 'remote.php/dav', path)
return fetcher(url, options)
return fetch(url, options)
}

/**
Expand All @@ -108,7 +99,7 @@ const requestOCSEndpoint = function(path, params, userId = 'admin', header = {})
'ocs/v2.php',
path + separator + 'format=json'
)
return fetcher(url, options)
return fetch(url, options)
}

module.exports = {
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/helpers/sharingHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ module.exports = {
.deleteOCS(apiURL, user)
.then(res => {
res = httpHelper.checkStatus(res, 'The response status is not the expected value')
console.log('deleted Share')
return res.json()
})
.then(res => {
Expand Down
47 changes: 34 additions & 13 deletions tests/acceptance/stepDefinitions/provisioningContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ async function createUser(
})
}

async function createUserWithAttributes(
{ username, password = false, displayname = false, email = false },
skeletonType = 'small',
initialize = false
) {
password = password || userSettings.getPasswordForUser(username)
await deleteUser(username)
await createUser(username, password, displayname, email, skeletonType)
if (initialize) {
await initUser(username)
}
}

function deleteUser(userId) {
userSettings.deleteUserFromCreatedUsersList(userId)
const url = `cloud/users/${userId}`
Expand Down Expand Up @@ -252,13 +265,19 @@ Given(
codify.replaceInlineTable(dataTable)
return Promise.all(
dataTable.hashes().map(user => {
const userId = user.username
const password = user.password || userSettings.getPasswordForUser(userId)
const displayName = user.displayname || false
const email = user.email || false
return deleteUser(userId).then(() =>
createUser(userId, password, displayName, email, skeletonType)
)
return createUserWithAttributes(user, skeletonType)
})
)
}
)

Given(
/^these users have been created with initialization and (without|small|large) skeleton files:$/,
function(skeletonType, dataTable) {
codify.replaceInlineTable(dataTable)
return Promise.all(
dataTable.hashes().map(user => {
return createUserWithAttributes(user, skeletonType, true)
})
)
}
Expand Down Expand Up @@ -324,13 +343,15 @@ After(async function() {
const createdGroups = userSettings.getCreatedGroups()

if (client.globals.ocis) {
const deleteSharePromises = createdUsers.map(user => {
return sharingHelper.getAllSharesSharedByUser(user).then(shares => {
if (shares.length) {
return Promise.all(shares.map(share => sharingHelper.deleteShare(share.id, user)))
const deleteSharePromises = []
for (const user of createdUsers) {
const shares = await sharingHelper.getAllSharesSharedByUser(user)
if (shares.length) {
for (const share of shares) {
await sharingHelper.deleteShare(share.id, user)
}
})
})
}
}
await Promise.all(deleteSharePromises).catch(err => {
console.log('Error while deleting shares after test: ', err)
})
Expand Down

0 comments on commit 567747b

Please sign in to comment.