mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 19:19:03 +01:00 
			
		
		
		
	Add ETAPI test to repro inherited attribute issue for cloned note #3994
This commit is contained in:
		
							parent
							
								
									758dba9ba5
								
							
						
					
					
						commit
						86a080e7ec
					
				
							
								
								
									
										142
									
								
								test-etapi/get-inherited-attribute-cloned-workaround.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								test-etapi/get-inherited-attribute-cloned-workaround.http
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,142 @@ | |||||||
|  | POST {{triliumHost}}/etapi/create-note | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "parentNoteId": "root", | ||||||
|  |   "title": "Hello parent", | ||||||
|  |   "type": "text", | ||||||
|  |   "content": "Hi there!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("parentNoteId", response.body.note.noteId); | ||||||
|  | client.global.set("parentBranchId", response.body.branch.branchId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create inheritable parent attribute | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/attributes | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{parentNoteId}}", | ||||||
|  |   "type": "label", | ||||||
|  |   "name": "mylabel", | ||||||
|  |   "value": "", | ||||||
|  |   "isInheritable": true, | ||||||
|  |   "position": 10 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("parentAttributeId", response.body.attributeId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create child note under root | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/create-note | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "parentNoteId": "root", | ||||||
|  |   "title": "Hello child", | ||||||
|  |   "type": "text", | ||||||
|  |   "content": "Hi there!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("childNoteId", response.body.note.noteId); | ||||||
|  | client.global.set("childBranchId", response.body.branch.branchId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create child attribute | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/attributes | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{childNoteId}}", | ||||||
|  |   "type": "label", | ||||||
|  |   "name": "mylabel", | ||||||
|  |   "value": "val", | ||||||
|  |   "isInheritable": false, | ||||||
|  |   "position": 10 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("childAttributeId", response.body.attributeId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Clone child to parent | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/branches | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{childNoteId}}", | ||||||
|  |   "parentNoteId": "{{parentNoteId}}" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.assert(response.body.parentNoteId == client.global.get("parentNoteId")); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Workaround: create dummy attribute | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/attributes | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{childNoteId}}", | ||||||
|  |   "type": "label", | ||||||
|  |   "name": "childlabel", | ||||||
|  |   "value": "val", | ||||||
|  |   "isInheritable": false | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("dummyAttributeId", response.body.attributeId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Workaround: delete dummy attribute | ||||||
|  | 
 | ||||||
|  | DELETE {{triliumHost}}/etapi/attributes/{{dummyAttributeId}} | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | 
 | ||||||
|  | > {% client.assert(response.status === 204); %} | ||||||
|  | 
 | ||||||
|  | ### | ||||||
|  | 
 | ||||||
|  | GET {{triliumHost}}/etapi/notes/{{childNoteId}} | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | 
 | ||||||
|  | function hasAttribute(list, attributeId) { | ||||||
|  |   for (let i = 0; i < list.length; i++) { | ||||||
|  |     if (list[i]["attributeId"] === attributeId) { | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | client.assert(response.status === 200); | ||||||
|  | client.assert(response.body.noteId == client.global.get("childNoteId")); | ||||||
|  | client.assert(response.body.attributes.length == 2); | ||||||
|  | client.assert(hasAttribute(response.body.attributes,  | ||||||
|  |   client.global.get("parentAttributeId"))); | ||||||
|  | client.assert(hasAttribute(response.body.attributes,  | ||||||
|  |   client.global.get("childAttributeId"))); | ||||||
|  | %} | ||||||
							
								
								
									
										116
									
								
								test-etapi/get-inherited-attribute-cloned.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								test-etapi/get-inherited-attribute-cloned.http
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,116 @@ | |||||||
|  | POST {{triliumHost}}/etapi/create-note | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "parentNoteId": "root", | ||||||
|  |   "title": "Hello parent", | ||||||
|  |   "type": "text", | ||||||
|  |   "content": "Hi there!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("parentNoteId", response.body.note.noteId); | ||||||
|  | client.global.set("parentBranchId", response.body.branch.branchId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create inheritable parent attribute | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/attributes | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{parentNoteId}}", | ||||||
|  |   "type": "label", | ||||||
|  |   "name": "mylabel", | ||||||
|  |   "value": "", | ||||||
|  |   "isInheritable": true, | ||||||
|  |   "position": 10 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("parentAttributeId", response.body.attributeId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create child note under root | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/create-note | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "parentNoteId": "root", | ||||||
|  |   "title": "Hello child", | ||||||
|  |   "type": "text", | ||||||
|  |   "content": "Hi there!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("childNoteId", response.body.note.noteId); | ||||||
|  | client.global.set("childBranchId", response.body.branch.branchId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Create child attribute | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/attributes | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{childNoteId}}", | ||||||
|  |   "type": "label", | ||||||
|  |   "name": "mylabel", | ||||||
|  |   "value": "val", | ||||||
|  |   "isInheritable": false, | ||||||
|  |   "position": 10 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.global.set("childAttributeId", response.body.attributeId); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### Clone child to parent | ||||||
|  | 
 | ||||||
|  | POST {{triliumHost}}/etapi/branches | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | Content-Type: application/json | ||||||
|  | 
 | ||||||
|  | { | ||||||
|  |   "noteId": "{{childNoteId}}", | ||||||
|  |   "parentNoteId": "{{parentNoteId}}" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | client.assert(response.status === 201); | ||||||
|  | client.assert(response.body.parentNoteId == client.global.get("parentNoteId")); | ||||||
|  | %} | ||||||
|  | 
 | ||||||
|  | ### | ||||||
|  | 
 | ||||||
|  | GET {{triliumHost}}/etapi/notes/{{childNoteId}} | ||||||
|  | Authorization: {{authToken}} | ||||||
|  | 
 | ||||||
|  | > {% | ||||||
|  | 
 | ||||||
|  | function hasAttribute(list, attributeId) { | ||||||
|  |   for (let i = 0; i < list.length; i++) { | ||||||
|  |     if (list[i]["attributeId"] === attributeId) { | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | client.assert(response.status === 200); | ||||||
|  | client.assert(response.body.noteId == client.global.get("childNoteId")); | ||||||
|  | client.assert(response.body.attributes.length == 2); | ||||||
|  | client.assert(hasAttribute(response.body.attributes,  | ||||||
|  |   client.global.get("parentAttributeId"))); | ||||||
|  | client.assert(hasAttribute(response.body.attributes,  | ||||||
|  |   client.global.get("childAttributeId"))); | ||||||
|  | %} | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 mm21
						mm21