Skip to content

Commit 7328537

Browse files
committed
updated tests with helper classes
1 parent a1078e1 commit 7328537

File tree

7 files changed

+180
-631
lines changed

7 files changed

+180
-631
lines changed

tests/src/map_holons/holons/common.ts

Lines changed: 109 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
import { CallableCell } from '@holochain/tryorama';
22
import { NewEntryAction, ActionHash, Record, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash, fakeDnaHash } from '@holochain/client';
3-
import { BaseValue, BaseValueList, DanceRequest, Holon, WithPropertyInput, DanceTypeEnum, RequestBodyEnum, DanceResponse, DanceType, RequestBody, DanceTypeObject, RequestBodyObject, TargetHolons, StagingArea, PropertyMap } from './types';
4-
5-
export function build_dance_request(danceName:string):DanceRequest {
6-
return {
7-
dance_name:danceName,
8-
dance_type:{[DanceTypeEnum.Standalone]:null},
9-
body: {[RequestBodyEnum.None]:null},
10-
staging_area: {staged_holons:[],index:{}}
11-
}
12-
}
3+
import { BaseValue, BaseValueList, DanceRequestObject, Holon, WithPropertyInput, DanceTypeEnum, RequestBodyEnum, DanceResponseObject, DanceType, RequestBody, DanceTypeObject, RequestBodyObject, TargetHolons, StagingArea, PropertyMap, ResponseStatusCode, ResponseBody, HolonReference, ResponseBodyEnum } from './types';
134

14-
export function send_dance_request(cell: CallableCell, name:string, type:DanceTypeObject, body:RequestBodyObject, stage:StagingArea):Promise<DanceResponse> {
15-
const data:DanceRequest = {
5+
6+
export function send_dance_request(cell: CallableCell, name:string, type:DanceTypeObject, body:RequestBodyObject):Promise<DanceResponseObject> {
7+
const data:DanceRequestObject = {
168
dance_name:name,
179
dance_type:type,
1810
body: body,
19-
staging_area: stage
11+
staging_area:{staged_holons:[],index:{}}
12+
2013
}
2114
return cell.callZome({zome_name: "dances", fn_name: "dance", payload: data})
2215
}
2316

24-
export async function sampleHolon(cell: CallableCell, partialHolon = {}) {
25-
return {
26-
...{
27-
descriptor: (await fakeActionHash()),
28-
},
29-
...partialHolon
30-
};
31-
}
3217

3318
export function createHolon(props:PropertyMap):Holon {
3419
return {
@@ -44,7 +29,7 @@ export function createHolon(props:PropertyMap):Holon {
4429
}
4530

4631

47-
export async function addProperty(cell: CallableCell, emptyholon: Holon, property:string = undefined, propertyvalue:BaseValueList = undefined): Promise<Holon> {
32+
export async function withProperty(cell: CallableCell, emptyholon: Holon, property:string = undefined, propertyvalue:BaseValueList = undefined): Promise<Holon> {
4833
const propertyObject: WithPropertyInput = { holon: emptyholon, property_name:property, value:propertyvalue }
4934
return cell.callZome({
5035
zome_name: "holons",
@@ -55,20 +40,109 @@ export async function addProperty(cell: CallableCell, emptyholon: Holon, propert
5540

5641

5742

58-
export async function sampleHolonNode(cell: CallableCell, partialHolonNode = {}) {
59-
return {
60-
...{
61-
dummy_field: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
62-
},
63-
...partialHolonNode
64-
};
43+
// alternative helper class
44+
export class DanceResponse {
45+
public status_code: ResponseStatusCode
46+
public description: string
47+
public body: ResponseBody
48+
public descriptor?: HolonReference // space_id+holon_id of DanceDescriptor
49+
private staging_area: StagingArea
50+
51+
constructor (private dr:DanceResponseObject){
52+
this.status_code = dr.status_code
53+
this.description = dr.description
54+
this.body = dr.body
55+
this.descriptor = dr.descriptor
56+
this.staging_area = dr.staging_area
57+
}
58+
59+
getStagedObjects(){
60+
return this.staging_area.staged_holons
61+
}
62+
63+
getStagedIndex(){
64+
return this.staging_area.index
65+
}
66+
//wip
67+
findIndexbyKey(key:string):number{
68+
if (this.body.type === ResponseBodyEnum.Holons)
69+
return 0
70+
return 0
71+
}
72+
6573
}
6674

67-
export async function createHolonNode(cell: CallableCell, holonNode = undefined): Promise<Record> {
68-
return cell.callZome({
69-
zome_name: "holons",
70-
fn_name: "create_holon_node",
71-
payload: holonNode || await sampleHolonNode(cell),
72-
});
75+
//helper classes
76+
export class DanceRequest {
77+
zome_name = "dances"
78+
zome_fn = "dance"
79+
cell:CallableCell
80+
staging_area: StagingArea = {staged_holons:[],index:{}}
81+
82+
constructor (private agent:CallableCell){
83+
this.cell = agent
84+
}
85+
86+
private async callzome(data:DanceRequestObject):Promise<DanceResponse> {
87+
const response:DanceResponseObject = await this.cell.callZome({zome_name: this.zome_name, fn_name: this.zome_fn, payload: data})
88+
this.staging_area = response.staging_area
89+
return new DanceResponse(response)
90+
}
91+
92+
// readall is standalone request with no parameters or properties
93+
public async readall(name:string):Promise<DanceResponse> {
94+
const dro:DanceRequestObject = {
95+
dance_name:name,
96+
dance_type:{[DanceTypeEnum.Standalone]:null},
97+
body:{[RequestBodyEnum.None]: null},
98+
staging_area:this.staging_area
99+
}
100+
return this.callzome(dro)
101+
}
102+
103+
/* create one using the stage request with no parameters or properties */
104+
public async createOneEmpty(name:string):Promise<DanceResponse> {
105+
const dro:DanceRequestObject = {
106+
dance_name:name,
107+
dance_type:{[DanceTypeEnum.Standalone]:null},
108+
body:{[RequestBodyEnum.None]: null},
109+
staging_area:this.staging_area
110+
}
111+
return this.callzome(dro)
112+
}
113+
114+
/* create one using the stage request with properties */
115+
public async createOne(name:string, data:Holon):Promise<DanceResponse> {
116+
const dro:DanceRequestObject = {
117+
dance_name:name,
118+
dance_type:{[DanceTypeEnum.Standalone]:null},
119+
body:{[RequestBodyEnum.Holon]: data},
120+
staging_area:this.staging_area
121+
}
122+
return this.callzome(dro)
123+
}
124+
125+
/// update an existing object by index with properties
126+
public async updateOneWithProperties(name:string, index:number, properties:PropertyMap):Promise<DanceResponse> {
127+
const dro:DanceRequestObject = {
128+
dance_name:name,
129+
dance_type:{[DanceTypeEnum.CommandMethod]:index},
130+
body:{[RequestBodyEnum.ParameterValues]: properties},
131+
staging_area:this.staging_area
132+
}
133+
return this.callzome(dro)
134+
}
135+
136+
// maybe this doesnt need any string variations?
137+
public async commit(name:string){
138+
const dro:DanceRequestObject = {
139+
dance_name:name,
140+
dance_type:{[DanceTypeEnum.Standalone]:null},
141+
body:{[RequestBodyEnum.None]: null},
142+
staging_area:this.staging_area
143+
}
144+
return this.callzome(dro)
145+
}
146+
73147
}
74148

tests/src/map_holons/holons/old/all-holon-nodes.testts

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/src/map_holons/holons/old/holon-node-to-holon-nodes.testts

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)