@@ -892,4 +892,90 @@ func TestSharedDrives(t *testing.T) {
892892 res .Header ("Content-Disposition" ).IsEqual (`attachment; filename="` + checklistName + `"` )
893893 })
894894 })
895+
896+ t .Run ("CreateAndOpenNote" , func (t * testing.T ) {
897+ eA := httpexpect .Default (t , tsA .URL )
898+ eB := httpexpect .Default (t , tsB .URL )
899+
900+ t .Run ("CreateNoteInSharedDrive" , func (t * testing.T ) {
901+ // Create a note in the shared drive as the owner
902+ obj := eA .POST ("/sharings/drives/" + sharingID + "/notes" ).
903+ WithHeader ("Authorization" , "Bearer " + acmeAppToken ).
904+ WithHeader ("Content-Type" , "application/json" ).
905+ WithBytes ([]byte (`{
906+ "data": {
907+ "type": "io.cozy.notes.documents",
908+ "attributes": {
909+ "title": "Meeting Minutes",
910+ "dir_id": "` + meetingsID + `",
911+ "schema": {
912+ "nodes": [
913+ ["doc", { "content": "block+" }],
914+ ["paragraph", { "content": "inline*", "group": "block" }],
915+ ["text", { "group": "inline" }],
916+ ["bullet_list", { "content": "list_item+", "group": "block" }],
917+ ["list_item", { "content": "paragraph block*" }]
918+ ],
919+ "marks": [
920+ ["em", {}],
921+ ["strong", {}]
922+ ],
923+ "topNode": "doc"
924+ }
925+ }
926+ }
927+ }` )).
928+ Expect ().Status (201 ).
929+ JSON (httpexpect.ContentOpts {MediaType : "application/vnd.api+json" }).
930+ Object ()
931+
932+ data := obj .Value ("data" ).Object ()
933+ data .HasValue ("type" , "io.cozy.files" )
934+ noteID := data .Value ("id" ).String ().NotEmpty ().Raw ()
935+
936+ attrs := data .Value ("attributes" ).Object ()
937+ attrs .HasValue ("type" , "file" )
938+ attrs .HasValue ("name" , "Meeting Minutes.cozy-note" )
939+ attrs .HasValue ("mime" , "text/vnd.cozy.note+markdown" )
940+
941+ meta := attrs .Value ("metadata" ).Object ()
942+ meta .HasValue ("title" , "Meeting Minutes" )
943+ meta .HasValue ("version" , 0 )
944+ meta .Value ("schema" ).Object ().NotEmpty ()
945+ meta .Value ("content" ).Object ().NotEmpty ()
946+
947+ t .Run ("OpenNoteFromSharedDrive" , func (t * testing.T ) {
948+ obj := eB .GET ("/sharings/drives/" + sharingID + "/notes/" + noteID + "/open" ).
949+ WithHeader ("Authorization" , "Bearer " + bettyAppToken ).
950+ Expect ().Status (200 ).
951+ JSON (httpexpect.ContentOpts {MediaType : "application/vnd.api+json" }).
952+ Object ()
953+
954+ data := obj .Value ("data" ).Object ()
955+ data .HasValue ("type" , consts .NotesURL )
956+ data .HasValue ("id" , noteID )
957+
958+ attrs := data .Value ("attributes" ).Object ()
959+ attrs .HasValue ("note_id" , noteID )
960+ attrs .HasValue ("subdomain" , "nested" )
961+ attrs .HasValue ("instance" , acmeInstance .Domain )
962+ attrs .Value ("public_name" ).String ().NotEmpty ()
963+ })
964+ })
965+
966+ t .Run ("CreateNoteWithoutAuthentication" , func (t * testing.T ) {
967+ eB .POST ("/sharings/drives/" + sharingID + "/notes" ).
968+ WithHeader ("Content-Type" , "application/json" ).
969+ WithBytes ([]byte (`{
970+ "data": {
971+ "type": "io.cozy.notes.documents",
972+ "attributes": {
973+ "title": "Unauthorized Note",
974+ "dir_id": "` + meetingsID + `"
975+ }
976+ }
977+ }` )).
978+ Expect ().Status (401 )
979+ })
980+ })
895981}
0 commit comments