Skip to content

Commit

Permalink
Fixed templates, tests working again
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Feb 19, 2024
1 parent fd0b606 commit cfcfc2d
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 142 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.cargo
target
.direnv
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ async fn create_and_read_{{snake_case entry_type.name}}() {

consistency_10s([&alice, &bobbo]).await;

{{#if crud.update}}
let get_record: Option<Record> = conductors[1]
.call(&bob_zome, "get_original_{{snake_case entry_type.name}}", record.signed_action.action_address().clone())
.await;
{{else}}
let get_record: Option<Record> = conductors[1]
.call(&bob_zome, "get_{{snake_case entry_type.name}}", {{#if entry_type.reference_entry_hash}}record.action().entry_hash().unwrap().clone(){{else}}record.signed_action.action_address().clone(){{/if}})
.await;
{{/if}}

assert_eq!(record, get_record.unwrap());
}
Expand Down Expand Up @@ -130,7 +136,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
consistency_10s([&alice, &bobbo]).await;

let get_record: Option<Record> = conductors[1]
.call(&bob_zome, "get_{{snake_case entry_type.name}}", original_action_hash.clone())
.call(&bob_zome, "get_latest_{{snake_case entry_type.name}}", original_action_hash.clone())
.await;

assert_eq!(update_record, get_record.unwrap());
Expand All @@ -154,7 +160,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
consistency_10s([&alice, &bobbo]).await;

let get_record: Option<Record> = conductors[1]
.call(&bob_zome, "get_{{snake_case entry_type.name}}", original_action_hash.clone())
.call(&bob_zome, "get_latest_{{snake_case entry_type.name}}", original_action_hash.clone())
.await;

assert_eq!(update_record, get_record.unwrap());
Expand Down Expand Up @@ -187,16 +193,17 @@ async fn create_and_delete_{{snake_case entry_type.name}}() {
let original_action_hash = record.signed_action.hashed.hash;

// Alice deletes the {{pascal_case entry_type.name}}
let _delete_action_hash: ActionHash = conductors[0]
let delete_action_hash: ActionHash = conductors[0]
.call(&alice_zome, "delete_{{snake_case entry_type.name}}", original_action_hash.clone())
.await;

consistency_10s([&alice, &bobbo]).await;

let get_record: Option<Record> = conductors[1]
.call(&bob_zome, "get_{{snake_case entry_type.name}}", original_action_hash.clone())
let deletes: Vec<SignedActionHashed> = conductors[1]
.call(&bob_zome, "get_all_deletes_for_{{snake_case entry_type.name}}", original_action_hash.clone())
.await;

assert!(get_record.is_none());
assert_eq!(deletes.len(), 1);
assert_eq!(deletes[0].hashed.hash, delete_action_hash);
}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hdk::prelude::*;
use holochain::test_utils::consistency_10s;
use holochain::{conductor::config::ConductorConfig, sweettest::*};

use hc_zome_{{snake_case coordinator_zome_manifest.name}}_coordinator::{{snake_case link_type_name}}::{{#if delete}}{Remove{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input, Add{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input }{{else}}Add{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input{{/if}};
use {{snake_case coordinator_zome_manifest.name}}::{{snake_case link_type_name}}::{{#if delete}}{Remove{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input, Add{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input }{{else}}Add{{pascal_case to_referenceable.name}}For{{pascal_case from_referenceable.name}}Input{{/if}};

{{#if (or (ne from_referenceable.hash_type "AgentPubKey") (ne to_referenceable.hash_type "AgentPubKey"))}}
mod common;
Expand Down Expand Up @@ -80,7 +80,7 @@ async fn link_a_{{snake_case from_referenceable.name}}_to_a_{{snake_case to_refe
assert_eq!(AnyLinkableHash::from(target_address.clone()), links_output[0].target);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}

// Bob gets the links in the inverse
let links_output: Vec<Link> = conductors[1]
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn link_a_{{snake_case from_referenceable.name}}_to_a_{{snake_case to_refe
let deleted_links_output: Vec<(SignedActionHashed, Vec<SignedActionHashed>)> = conductors[1]
.call(&bob_zome, "get_deleted_{{plural (snake_case to_referenceable.name)}}_for_{{snake_case from_referenceable.name}}", base_address.clone()).await;
assert_eq!(deleted_links_output.len(), 1);
{{#if bidireccional}}
{{#if bidirectional}}

// Bob gets the links in the inverse
let links_output: Vec<Link> = conductors[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('link a {{pascal_case from_referenceable.name}} to a {{pascal_case to_refer
assert.deepEqual(targetAddress, Array.from(linksOutput.keys())[0]);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
// Bob gets the links in the inverse direction
let inverseLinksOutput = await toPromise(bob.store.{{#if (ne to_referenceable.hash_type "ActionHash")}}{{camel_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.get(targetAddress){{else}}{{camel_case (plural to_referenceable.name)}}.get(targetAddress).{{camel_case (plural from_referenceable.name)}}{{/if}}{{#if delete}}.live{{/if}});
{{#if (eq from_referenceable.hash_type "AgentPubKey")}}
Expand Down Expand Up @@ -102,7 +102,7 @@ test('link a {{pascal_case from_referenceable.name}} to a {{pascal_case to_refer
assert.equal(deletedLinksOutput.size, 1);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
// Bob gets the links in the inverse direction
inverseLinksOutput = await toPromise(bob.store.{{#if (ne to_referenceable.hash_type "ActionHash")}}{{camel_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.get(targetAddress){{else}}{{camel_case (plural to_referenceable.name)}}.get(targetAddress).{{camel_case (plural from_referenceable.name)}}{{/if}}{{#if delete}}.live{{/if}});
{{#if (eq from_referenceable.hash_type "AgentPubKey")}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/** {{title_case (plural to_referenceable.name)}} for {{title_case from_referenceable.name}} */
{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}} = new HoloHashMap<{{from_referenceable.hash_type}}, Link[]>();
{{#if bidireccional}}
{{#if bidirectional}}
{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}} = new HoloHashMap<{{to_referenceable.hash_type}}, Link[]>();
{{/if}}

Expand All @@ -23,7 +23,7 @@
tag: new Uint8Array(),
create_link_hash: await fakeActionHash()
}]);
{{#if bidireccional}}
{{#if bidirectional}}
const existingReverse = this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get(input.{{snake_case to_referenceable.singular_arg}}) || [];
this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.set(input.{{snake_case to_referenceable.singular_arg}}, [...existingReverse, {
target: input.{{snake_case from_referenceable.singular_arg}},
Expand All @@ -37,7 +37,7 @@
{{/if}}
}

{{#if bidireccional}}
{{#if bidirectional}}
async get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<Link>> {
return this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get({{camel_case to_referenceable.singular_arg}}) || [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

{{/if}}
{{#if bidireccional}}
{{#if bidirectional}}
async get{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<Link>> {
return this.callZome('get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}', {{camel_case to_referenceable.singular_arg}});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
),
{{/if}}
{{/match_scope}}
{{#if bidireccional}}
{{#if bidirectional}}
{{#if (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ) }}
{{#match_scope (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" )}}
{{previous_scope_content}}
Expand Down Expand Up @@ -102,7 +102,7 @@
{{/if}}
{{/merge}}
{{else}}
{{#if (or (not bidireccional) (not (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ))))}}
{{#if (or (not bidirectional) (not (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ))))}}
{{previous_scope_content}}
{{/if}}

Expand Down Expand Up @@ -150,7 +150,7 @@
){{/if}});
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
{{#if (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) )) }}
{{#merge previous_scope_content}}
{{#match_scope (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" )}}
Expand Down
1 change: 1 addition & 0 deletions .templates/app/web-app/.envrc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
2 changes: 2 additions & 0 deletions .templates/app/web-app/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ storybook-static
# cargo
/target/
/.cargo/

.direnv/
1 change: 1 addition & 0 deletions .templates/app/web-app/flake.nix.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
packages = with pkgs; [
nodejs-18_x
cargo-nextest
binaryen
];
{{/match_scope}}
{{/merge}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use holochain::{conductor::config::ConductorConfig, sweettest::*};
use {{snake_case coordinator_zome_manifest.name}}_integrity::*;

{{#if crud.update}}
use hc_zome_{{snake_case coordinator_zome_manifest.name}}_coordinator::{{snake_case entry_type.name}}::Update{{pascal_case entry_type.name}}Input;
use {{snake_case coordinator_zome_manifest.name}}::{{snake_case entry_type.name}}::Update{{pascal_case entry_type.name}}Input;
{{/if}}

mod common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('link a {{pascal_case from_referenceable.name}} to a {{pascal_case to_refer
assert.deepEqual(targetAddress, Array.from(linksOutput.keys())[0]);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
// Bob gets the links in the inverse direction
let inverseLinksOutput = await toPromise(bob.store.{{#if (ne to_referenceable.hash_type "ActionHash")}}{{camel_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.get(targetAddress){{else}}{{camel_case (plural to_referenceable.name)}}.get(targetAddress).{{camel_case (plural from_referenceable.name)}}{{/if}}{{#if delete}}.live{{/if}});
{{#if (eq from_referenceable.hash_type "AgentPubKey")}}
Expand Down Expand Up @@ -102,7 +102,7 @@ test('link a {{pascal_case from_referenceable.name}} to a {{pascal_case to_refer
assert.equal(deletedLinksOutput.size, 1);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
// Bob gets the links in the inverse direction
inverseLinksOutput = await toPromise(bob.store.{{#if (ne to_referenceable.hash_type "ActionHash")}}{{camel_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}.get(targetAddress){{else}}{{camel_case (plural to_referenceable.name)}}.get(targetAddress).{{camel_case (plural from_referenceable.name)}}{{/if}}{{#if delete}}.live{{/if}});
{{#if (eq from_referenceable.hash_type "AgentPubKey")}}
Expand Down
6 changes: 3 additions & 3 deletions .templates/module/link-type/ui/src/mocks.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/** {{title_case (plural to_referenceable.name)}} for {{title_case from_referenceable.name}} */
{{camel_case from_referenceable.name}}To{{pascal_case to_referenceable.name}} = new HoloHashMap<{{from_referenceable.hash_type}}, Link[]>();
{{#if bidireccional}}
{{#if bidirectional}}
{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}} = new HoloHashMap<{{to_referenceable.hash_type}}, Link[]>();
{{/if}}

Expand All @@ -23,7 +23,7 @@
tag: new Uint8Array(),
create_link_hash: await fakeActionHash()
}]);
{{#if bidireccional}}
{{#if bidirectional}}
const existingReverse = this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get(input.{{snake_case to_referenceable.singular_arg}}) || [];
this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.set(input.{{snake_case to_referenceable.singular_arg}}, [...existingReverse, {
target: input.{{snake_case from_referenceable.singular_arg}},
Expand All @@ -37,7 +37,7 @@
{{/if}}
}

{{#if bidireccional}}
{{#if bidirectional}}
async get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<Link>> {
return this.{{camel_case to_referenceable.name}}To{{pascal_case from_referenceable.name}}.get({{camel_case to_referenceable.singular_arg}}) || [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

{{/if}}
{{#if bidireccional}}
{{#if bidirectional}}
async get{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}({{camel_case to_referenceable.singular_arg}}: {{to_referenceable.hash_type}}): Promise<Array<Link>> {
return this.callZome('get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}', {{camel_case to_referenceable.singular_arg}});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
),
{{/if}}
{{/match_scope}}
{{#if bidireccional}}
{{#if bidirectional}}
{{#if (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ) }}
{{#match_scope (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" )}}
{{previous_scope_content}}
Expand Down Expand Up @@ -102,7 +102,7 @@
{{/if}}
{{/merge}}
{{else}}
{{#if (or (not bidireccional) (not (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ))))}}
{{#if (or (not bidirectional) (not (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) ))))}}
{{previous_scope_content}}
{{/if}}

Expand Down Expand Up @@ -150,7 +150,7 @@
){{/if}});
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}
{{#if (and (not (includes previous_file_content (concat (camel_case (plural from_referenceable.name)) " = new LazyHoloHashMap((" (camel_case from_referenceable.name) "Hash: " from_referenceable.hash_type ") => ({" ) )) (includes previous_file_content (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" ) )) }}
{{#merge previous_scope_content}}
{{#match_scope (concat (camel_case (plural to_referenceable.name)) " = new LazyHoloHashMap((" (camel_case to_referenceable.name) "Hash: " to_referenceable.hash_type ") => ({" )}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn link_a_{{snake_case from_referenceable.name}}_to_a_{{snake_case to_refe
assert_eq!(AnyLinkableHash::from(target_address.clone()), links_output[0].target);
{{/if}}

{{#if bidireccional}}
{{#if bidirectional}}

// Bob gets the links in the inverse
let links_output: Vec<Link> = conductors[1]
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn link_a_{{snake_case from_referenceable.name}}_to_a_{{snake_case to_refe
let deleted_links_output: Vec<(SignedActionHashed, Vec<SignedActionHashed>)> = conductors[1]
.call(&bob_zome, "get_deleted_{{plural (snake_case to_referenceable.name)}}_for_{{snake_case from_referenceable.name}}", base_address.clone()).await;
assert_eq!(deleted_links_output.len(), 1);
{{#if bidireccional}}
{{#if bidirectional}}

// Bob gets the links in the inverse
let links_output: Vec<Link> = conductors[1]
Expand Down
1 change: 1 addition & 0 deletions .templates/module/web-app/.envrc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
2 changes: 2 additions & 0 deletions .templates/module/web-app/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ storybook-static
# cargo
/target/
/.cargo/

/.direnv/
1 change: 1 addition & 0 deletions .templates/module/web-app/flake.nix.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
packages = with pkgs; [
nodejs-18_x
cargo-nextest
binaryen
];
{{/match_scope}}
{{/merge}}
Expand Down
Loading

0 comments on commit cfcfc2d

Please sign in to comment.