This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
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.
* feat: Unshare file (#89) * feat: add unshare file method to the repository * feat: add endpoint unshare file * fix: repair path route unshare metadata * feat: add utils unshare and generate Unshare * feat: add test unshare * refactor: update messages exeptions * docs(http): Update bruno collection --------- Co-authored-by: Pedro Andrés Chaparro Quintero <pedro.chaparro.2020@upb.edu.co> Co-authored-by: Sergio Daniel Baron Cabrera <47455237+sdbaronc@users.noreply.github.com>
- Loading branch information
1 parent
6a405fc
commit 08ee51e
Showing
11 changed files
with
318 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
meta { | ||
name: unshare-file | ||
type: http | ||
seq: 1 | ||
} | ||
|
||
post { | ||
url: {{BASE_URL}}/files/unshare/5c8e5e9d-7d82-450f-9fe3-43fc73aa5a39/76c5a635-08c4-46c9-89ef-89c120e2e55f | ||
body: json | ||
auth: none | ||
} | ||
|
||
body:json { | ||
{ | ||
"otherUserUUID": "e1139bb6-d291-4170-8fb0-94dd787fa84b" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package org.hawksatlanta.metadata | ||
package files_metadata | ||
|
||
import java.util.UUID | ||
|
||
import org.junit.runner.manipulation.Alphanumeric | ||
import org.junit.runner.OrderWith | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.scalatestplus.junit.JUnitSuite | ||
|
||
object UnShareFileTestsData { | ||
val API_PREFIX: String = "/api/v1/files/unshare" | ||
val OWNER_USER_UUID: UUID = UUID.randomUUID() | ||
val OTHER_USER_UUID: UUID = UUID.randomUUID() | ||
|
||
private var unsharePayload: java.util.HashMap[String, Any] = _ | ||
var savedDirectoryUUID: UUID = _ | ||
var savedFileUUID: UUID = _ | ||
var sharedFileUUID: UUID = _ | ||
var sharedDirectoryUUID: UUID = _ | ||
|
||
def getUnsharePayload(): java.util.HashMap[String, Any] = { | ||
if (unsharePayload == null) { | ||
unsharePayload = FilesTestsUtils.generateUnshareFilePayload( | ||
otherUserUUID = OTHER_USER_UUID | ||
) | ||
} | ||
|
||
unsharePayload.clone().asInstanceOf[java.util.HashMap[String, Any]] | ||
} | ||
} | ||
|
||
@OrderWith( classOf[Alphanumeric] ) | ||
class UnShareFileTests extends JUnitSuite { | ||
def saveFilesAndShareToUnhare(): Unit = { | ||
// Save a file to share | ||
val saveFilePayload = FilesTestsUtils.generateFilePayload( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID, | ||
parentDirUUID = None | ||
) | ||
|
||
val saveFileResponse = FilesTestsUtils.SaveFile( saveFilePayload ) | ||
UnShareFileTestsData.savedFileUUID = | ||
UUID.fromString( saveFileResponse.jsonPath().get( "uuid" ) ) | ||
|
||
// Save a directory to share | ||
val saveDirectoryPayload = FilesTestsUtils.generateDirectoryPayload( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID, | ||
parentDirUUID = None | ||
) | ||
|
||
val saveDirectoryResponse = | ||
FilesTestsUtils.SaveFile( saveDirectoryPayload ) | ||
UnShareFileTestsData.savedDirectoryUUID = | ||
UUID.fromString( saveDirectoryResponse.jsonPath().get( "uuid" ) ) | ||
|
||
val ShareFilePayload = FilesTestsUtils.generateShareFilePayload( | ||
otherUserUUID = UnShareFileTestsData.OTHER_USER_UUID | ||
) | ||
val ShareFileResponse = FilesTestsUtils.ShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedFileUUID.toString, | ||
payload = ShareFilePayload | ||
) | ||
val ShareDirectoryPayload = FilesTestsUtils.generateShareFilePayload( | ||
otherUserUUID = UnShareFileTestsData.OTHER_USER_UUID | ||
) | ||
val ShareDirectoryResponse = FilesTestsUtils.ShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedDirectoryUUID.toString, | ||
payload = ShareDirectoryPayload | ||
) | ||
|
||
} | ||
|
||
@Before | ||
def startHttpServer(): Unit = { | ||
FilesTestsUtils.StartHttpServer() | ||
} | ||
@Test | ||
def T1_UnShareFileBadRequest(): Unit = { | ||
saveFilesAndShareToUnhare() | ||
// 1. Bad other user | ||
val requestBody = ShareFileTestsData.getSharePayload() | ||
requestBody.put( "otherUserUUID", "Not an UUID" ) | ||
val response = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedFileUUID.toString, | ||
payload = requestBody | ||
) | ||
assert( response.statusCode() == 400 ) | ||
assert( response.jsonPath().getBoolean( "error" ) ) | ||
// 2. Bad ownerUserUUID | ||
val response2 = FilesTestsUtils.UnShareFile( | ||
ownerUUID = "Not an UUID", | ||
fileUUID = UnShareFileTestsData.savedFileUUID.toString, | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( response2.statusCode() == 400 ) | ||
assert( response2.jsonPath().getBoolean( "error" ) ) | ||
// 3. Bad fileUUID | ||
val response3 = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = "Not an UUID", | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( response3.statusCode() == 400 ) | ||
assert( response3.jsonPath().getBoolean( "error" ) ) | ||
} | ||
@Test | ||
def T2_UnshareSuccess(): Unit = { | ||
// Unshare the File | ||
val fileResponse = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedFileUUID.toString, | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( fileResponse.statusCode() == 204 ) | ||
// Unshare the File | ||
val fileResponse2 = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedDirectoryUUID.toString, | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( fileResponse2.statusCode() == 204 ) | ||
} | ||
|
||
@Test | ||
def T3_UnshareFileNotFound(): Unit = { | ||
val response = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OWNER_USER_UUID.toString, | ||
fileUUID = UUID.randomUUID().toString, | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( response.statusCode() == 404 ) | ||
assert( response.jsonPath().getBoolean( "error" ) ) | ||
} | ||
|
||
@Test | ||
def T4_ShareFileForbidden(): Unit = { | ||
val response = FilesTestsUtils.UnShareFile( | ||
ownerUUID = UnShareFileTestsData.OTHER_USER_UUID.toString, | ||
fileUUID = UnShareFileTestsData.savedFileUUID.toString, | ||
payload = UnShareFileTestsData.getUnsharePayload() | ||
) | ||
assert( response.statusCode() == 403 ) | ||
assert( response.jsonPath().getBoolean( "error" ) ) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "0.11.1" | ||
"version": "0.12.0" | ||
} |