-
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.
fix: document updates to work in cases user role is changed (#73)
- Loading branch information
Showing
10 changed files
with
154 additions
and
17 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
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
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
114 changes: 114 additions & 0 deletions
114
...search-solr-client/src/test/scala/io/renku/search/solr/documents/PartialProjectSpec.scala
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,114 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.solr.documents | ||
|
||
import io.renku.search.GeneratorSyntax | ||
import io.renku.search.model.ModelGenerators.{idGen, projectMemberRoleGen} | ||
import io.renku.search.model.projects | ||
import io.renku.search.model.projects.MemberRole.{Member, Owner} | ||
import io.renku.search.solr.client.SolrDocumentGenerators.partialProjectGen | ||
import io.renku.search.solr.documents.PartialEntityDocument.Project | ||
import munit.{FunSuite, ScalaCheckSuite} | ||
import org.scalacheck.Prop | ||
|
||
class PartialProjectSpec extends ScalaCheckSuite with GeneratorSyntax: | ||
|
||
test("add should add the userId to the relevant bucket"): | ||
Prop.forAll(partialProjectGen, idGen, projectMemberRoleGen) { | ||
case (existing, userId, role) => | ||
val updated = existing.add(userId, role) | ||
|
||
role match { | ||
case Owner => | ||
assertEquals(updated.owners, existing.owners + userId) | ||
assertEquals(updated.members, existing.members) | ||
case Member => | ||
assertEquals(updated.members, existing.members + userId) | ||
assertEquals(updated.owners, existing.owners) | ||
} | ||
} | ||
|
||
test( | ||
"add should add the userId to the relevant bucket and remove from the other bucket if existed" | ||
): | ||
Prop.forAll(idGen, idGen, projectMemberRoleGen) { case (projectId, userId, role) => | ||
val existing = Project(projectId, Set(userId), Set(userId)) | ||
|
||
val updated = existing.add(userId, role) | ||
|
||
role match { | ||
case Owner => | ||
assertEquals(updated.owners, existing.owners) | ||
assertEquals(updated.members, existing.members - userId) | ||
case Member => | ||
assertEquals(updated.members, existing.members) | ||
assertEquals(updated.owners, existing.owners - userId) | ||
} | ||
} | ||
|
||
test("applyTo should add members and owners from the caller object"): | ||
Prop.forAll(partialProjectGen, idGen, projectMemberRoleGen) { | ||
case (existing, userId, role) => | ||
val update = Project(existing.id).add(userId, role) | ||
|
||
val updated = existing.applyTo(update).asInstanceOf[Project] | ||
|
||
role match { | ||
case Owner => | ||
assertEquals(updated.owners, existing.owners + userId) | ||
assertEquals(updated.members, existing.members) | ||
case Member => | ||
assertEquals(updated.members, existing.members + userId) | ||
assertEquals(updated.owners, existing.owners) | ||
} | ||
} | ||
|
||
test( | ||
"applyTo should add members and owners from the caller object except those that have been moved between buckets" | ||
): | ||
Prop.forAll(idGen, idGen, projectMemberRoleGen) { case (projectId, userId, role) => | ||
val existing = Project(projectId, Set(userId), Set(userId)) | ||
|
||
val update = Project(projectId).add(userId, role) | ||
|
||
val updated = existing.applyTo(update).asInstanceOf[Project] | ||
|
||
role match { | ||
case Owner => | ||
assertEquals(updated.owners, existing.owners) | ||
assertEquals(updated.members, existing.members - userId) | ||
case Member => | ||
assertEquals(updated.members, existing.members) | ||
assertEquals(updated.owners, existing.owners - userId) | ||
} | ||
} | ||
|
||
test("removeMember should remove the given userId from the correct bucket in the doc"): | ||
Prop.forAll(partialProjectGen, idGen, projectMemberRoleGen) { | ||
case (project, userId, role) => | ||
val updated = project.add(userId, role) | ||
assertEquals(updated.remove(userId), project) | ||
} | ||
|
||
test("removeMember should do nothing if there's no member/owner with the given userId"): | ||
Prop.forAll(partialProjectGen, idGen, idGen, projectMemberRoleGen) { | ||
case (project, existingUserId, toDeleteUserId, role) => | ||
val updated = project.add(existingUserId, role) | ||
assertEquals(updated.remove(toDeleteUserId), updated) | ||
} |
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