Skip to content

Commit

Permalink
Refactor Tests (#1677)
Browse files Browse the repository at this point in the history
* refactor (refcatorTest) move the check for the format of IRI from E2E test to MessageADMSpec

* refactor (tests) correct typos in request parameters

* refactor (tests) add exceptions for missing shortcode and shortname, test them

* refactor (tests) remove empty lines and logs

* refactor (refactorTests) add BUILD.bazel to each messages test

* refactor (tests) add BUILD.bazel to specs of store messages

* refactor (tests) add BUILD.bazel to specs of v1 messages

* refactor (tests) add BUILD.bazel to tests of v2 messages

* refactor (tests) add BUILD.basel to "other" tests

* docs (refactorTests) correct the indentation problems in docs

* refactor syntax highlighting in docs

* refactor (tests) fix the failing test

* refactor (tests) add a test file for groupMessageADMSpec, BUILD.bazel for it, Move validation of custom IRI to it

* refactor (tests) move custom IRI validation to ListsMessagesADMSpec

* refactor (tests) move custom IRI validation to UsersMessagesADMSpec

* refactor (tests) correct signature of the test

* refactor (tests) remove validation of group IRI from E2E

* refactor (tests) correct signature

* refactor (tests) correct the example in UpdateGroupName docs

* refactor (tests) add new lines at the end of the file
  • Loading branch information
SepidehAlassi committed Jul 15, 2020
1 parent 175972b commit 49bedbe
Show file tree
Hide file tree
Showing 25 changed files with 408 additions and 321 deletions.
18 changes: 10 additions & 8 deletions docs/03-apis/api-admin/groups.md
Expand Up @@ -48,18 +48,20 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- POST: `/admin/groups`
- BODY:

```JSON
```json
{
"name": "NewGroup",
"description": "NewGroupDescription",
"project": "http://rdfh.ch/projects/00FF",
"status": true,
"selfjoin": false
}
```
Additionally, each group can have an optional custom IRI (of @ref:[Knora IRI](../api-v2/knora-iris.md#iris-for-data) form)
specified by the `id` in the request body as below:
```JSON
```

Additionally, each group can have an optional custom IRI (of @ref:[Knora IRI](../api-v2/knora-iris.md#iris-for-data) form)
specified by the `id` in the request body as below:

```json
{
"id": "http://rdfh.ch/groups/00FF/group-with-custom-Iri",
"name": "GroupWithCustomIRI",
Expand All @@ -68,7 +70,7 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"status": true,
"selfjoin": false
}
```
```

### Update group information

Expand All @@ -80,10 +82,10 @@ hasProjectRestrictedGroupAdminPermission (for this group)
- PUT: `/admin/groups/<groupIri>`
- BODY:

```
```json
{
"name": "UpdatedGroupName",
"description": "UpdatedGroupDescription".
"description": "UpdatedGroupDescription",
"selfjoin": false
}
```
Expand Down
23 changes: 14 additions & 9 deletions docs/03-apis/api-admin/lists.md
Expand Up @@ -57,22 +57,25 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- Required permission: SystemAdmin / ProjectAdmin
- POST: `/admin/lists`
- BODY:
```JSON

```json
{
"projectIri": "someprojectiri",
"labels": [{ "value": "Neue Liste", "language": "de"}],
"comments": []
}
```
Additionally, each list can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form) specified by the `id` in the request body as below:
```JSON
```

Additionally, each list can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form) specified by the `id` in the request body as below:

```json
{
"id": "http://rdfh.ch/lists/0001/a-list-with-IRI",
"projectIri": "http://rdfh.ch/projects/0001",
"labels": [{ "value": "Neue Liste mit IRI", "language": "de"}],
"comments": []
}
```
```

### Create new child node

Expand All @@ -82,15 +85,16 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
are currently only appended.
- POST: `/admin/lists/<nodeIri>`
- BODY:
```

```json
{
"parentNodeIri": "nodeIri",
"projectIri": "someprojectiri",
"name": "first",
"labels": [{ "value": "New First Child List Node Value", "language": "en"}],
"comments": [{ "value": "New First Child List Node Comment", "language": "en"}]
}
```
```

### Get list's information

Expand All @@ -104,14 +108,15 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- Update list information
- PUT: `/admin/lists/infos/<listIri>`
- BODY:
```

```json
{
"listIri": "listIri",
"projectIri": "someprojectiri",
"labels": [{ "value": "Neue geönderte Liste", "language": "de"}, { "value": "Changed list", "language": "en"}],
"comments": [{ "value": "Neuer Kommentar", "language": "de"}, { "value": "New comment", "language": "en"}]
}
```
```

## List Node Operations

Expand Down
22 changes: 15 additions & 7 deletions docs/03-apis/api-admin/projects.md
Expand Up @@ -63,13 +63,17 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- Optional information: longname, description, keywords, logo
- Returns information about the newly created project
- Remark: There are two distinct use cases / payload combination:

(1) change ontology and data graph: ontologygraph, datagraph,

(2) basic project information: shortname, longname, description,
keywords, logo, institution, status, selfjoin

- TypeScript Docs: projectFormats - CreateProjectApiRequestV1
- POST: `/admin/projects/`
- BODY:
```JSON

```json
{
"shortname": "newproject",
"longname": "project longname",
Expand All @@ -79,9 +83,11 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"status": true,
"selfjoin": false
}
```
Additionally, each project can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form) specified by the `id` in the request body as below:
```JSON
```

Additionally, each project can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form) specified by the `id` in the request body as below:

```json
{
"id": "http://rdfh.ch/projects/3333",
"shortname": "newprojectWithIri",
Expand All @@ -93,7 +99,8 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"status": true,
"selfjoin": false
}
```
```

### Update project information:

- Required permission: SystemAdmin / ProjectAdmin
Expand All @@ -102,7 +109,8 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- TypeScript Docs: projectFormats - ChangeProjectApiRequestV1
- PUT: `/admin/projects/iri/<projectIri>`
- BODY:
```JSON

```json
{
"shortname": "newproject",
"longname": "project longname",
Expand All @@ -112,7 +120,7 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"status": true,
"selfjoin": false
}
```
```

### Delete project (update project status):

Expand Down
36 changes: 21 additions & 15 deletions docs/03-apis/api-admin/users.md
Expand Up @@ -67,7 +67,7 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.

- Required permission: none, self-registration is allowed
- Required information: email (unique), given name, family name,
password, password, status, systemAdmin
password, status, systemAdmin
- Username restrictions:
- 4 - 50 characters long
- Only contains alphanumeric characters, underscore and dot.
Expand All @@ -77,7 +77,8 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- TypeScript Docs: userFormats - `CreateUserApiRequestV1`
- POST: `/admin/users`
- BODY:
```JSON

```json
{
"email": "donald.duck@example.org",
"givenName": "Donald",
Expand All @@ -88,11 +89,12 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"lang": "en",
"systemAdmin": false
}
```
```

Additionally, each user can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form)
specified by the `id` in the request body as below:
```JSON
Additionally, each user can have an optional custom IRI (of [Knora IRI](../api-v2/knora-iris.md#iris-for-data) form)
specified by the `id` in the request body as below:

```json
{
"id" : "http://rdfh.ch/users/donaldDuck",
"email": "donald.duck@example.org",
Expand All @@ -104,7 +106,7 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
"lang": "en",
"systemAdmin": false
}
```
```
### Update basic user information**

Expand All @@ -114,28 +116,30 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- TypeScript Docs: userFormats - ChangeUserApiRequestADM
- PUT: `/admin/users/iri/<userIri>/BasicUserInformation`
- BODY:
```

```json
{
"username": "donald.big.duck",
"email": "donald.big.duck@example.org",
"givenName": "Big Donald",
"familyName": "Duckmann",
"lang": "de"
}
```
```

### Update user's password

- Required permission: SystemAdmin / self
- Changeable information: password
- PUT: `/admin/users/iri/<userIri>/Password`
- BODY:
```

```json
{
"requesterPassword": "test",
"newPassword": "test1234"
}
```
```

### Delete user

Expand All @@ -144,11 +148,12 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
`false`. To un-delete, set `status` to `true`.
- PUT: `/admin/users/iri/<userIri>/Status`
- BODY:
```

```
{
"status": false // true or false
}
```
```

### Delete user (-\update user)**

Expand Down Expand Up @@ -210,11 +215,12 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
`true` or `false`
- PUT: `/admin/users/iri/<userIri>/SystemAdmin`
- BODY:
```JSON

```
{
"systemAdmin": false
}
```
```

## Example Data

Expand Down
Expand Up @@ -62,9 +62,8 @@ case class CreateProjectApiRequestADM(id: Option[IRI] = None,
implicit protected val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
def toJsValue: JsValue = createProjectApiRequestADMFormat.write(this)

if (description.isEmpty) {
throw BadRequestException("Project description needs to be supplied.")
}
if (description.isEmpty) throw BadRequestException("Project description needs to be supplied.")

stringFormatter.validateOptionalProjectIri(id, throw BadRequestException(s"Invalid project IRI"))
}

Expand Down
Expand Up @@ -88,25 +88,6 @@ class GroupsADME2ESpec extends E2ESpec(GroupsADME2ESpec.config) with GroupsADMJs
result.id should be ("http://rdfh.ch/groups/00FF/group-with-customIri")
}

"return 'BadRequest' if the supplied 'id' is not a valid IRI" in {
val params =
s"""{ "id": "invalid-group-IRI",
| "name": "NewGroupWithInvalidCustomIri",
| "description": "A new group with an invalid custom Iri",
| "project": "${SharedTestDataADM.IMAGES_PROJECT_IRI}",
| "status": true,
| "selfjoin": false
|}""".stripMargin


val request = Post(baseApiUrl + s"/admin/groups", HttpEntity(ContentTypes.`application/json`, params)) ~> addCredentials(BasicHttpCredentials(imagesUser01Email, testPass))
val response: HttpResponse = singleAwaitingRequest(request)
response.status should be (StatusCodes.BadRequest)
val errorMessage : String = Await.result(Unmarshal(response.entity).to[String], 1.second)
val invalidIri: Boolean = errorMessage.contains(s"Invalid group IRI")
invalidIri should be(true)
}

"return 'BadRequest' if the supplied IRI for the group is not unique" in {
val params =
s"""{ "id": "http://rdfh.ch/groups/00FF/group-with-customIri",
Expand Down
Expand Up @@ -171,27 +171,6 @@ class ListsADME2ESpec extends E2ESpec(ListsADME2ESpec.config) with SessionJsonPr
labels.head should be (StringLiteralV2(value = "New list with a custom IRI", language = Some("en")))
}

"return a BadRequestException during list creation when an invalid list IRI is given" in {

// invalid list IRI
val params =
s"""
|{
| "id": "invalid-list-IRI",
| "projectIri": "${SharedTestDataADM.ANYTHING_PROJECT_IRI}",
| "labels": [{ "value": "New List", "language": "en"}],
| "comments": []
|}
""".stripMargin

val request = Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params)) ~> addCredentials(anythingAdminUserCreds.basicHttpCredentials)
val response: HttpResponse = singleAwaitingRequest(request)
response.status should be(StatusCodes.BadRequest)
val errorMessage : String = Await.result(Unmarshal(response.entity).to[String], 1.second)
val invalidIri: Boolean = errorMessage.contains("Invalid list IRI")
invalidIri should be(true)
}

"return a DuplicateValueException during list creation when the supplied list IRI is not unique" in {

// duplicate list IRI
Expand Down

0 comments on commit 49bedbe

Please sign in to comment.