Skip to content

Commit

Permalink
debug recipe tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed Dec 16, 2023
1 parent 551b33a commit a6a3476
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 16 deletions.
1 change: 1 addition & 0 deletions modules/vf-graphql-holochain/queries/recipeFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default (dnaConfig: DNAIdMappings, conductorUri: string) => {

return {
recipeFlow: async (root, args): Promise<RecipeFlow> => {
console.log("recipeFlow", args)
return (await readOne({ address: args.id })).recipeFlow
},
recipeFlows: async (root, args: PagingParams): Promise<RecipeFlowConnection> => {
Expand Down
8 changes: 5 additions & 3 deletions modules/vf-graphql-holochain/queries/recipeProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import {
import { PagingParams } from '../resolvers/zomeSearchInputTypes.js'

export default (dnaConfig: DNAIdMappings, conductorUri: string) => {
const readOne = mapZomeFn<ReadParams, RecipeProcessResponse>(dnaConfig, conductorUri, 'planning', 'recipe_process', 'get_recipe_process')
const readAll = mapZomeFn<PagingParams, RecipeProcessConnection>(dnaConfig, conductorUri, 'planning', 'recipe_process_index', 'read_all_recipe_processs')
const readOne = mapZomeFn<ReadParams, RecipeProcessResponse>(dnaConfig, conductorUri, 'recipe', 'recipe_process', 'get_recipe_process')
const readAll = mapZomeFn<PagingParams, RecipeProcessConnection>(dnaConfig, conductorUri, 'recipe', 'recipe_process_index', 'read_all_recipe_processes')

return {
recipeProcess: async (root, args): Promise<RecipeProcess> => {
console.log("recipeProcess", args)
return (await readOne({ address: args.id })).recipeProcess
},
recipeProcesss: async (root, args: PagingParams): Promise<RecipeProcessConnection> => {
recipeProcesses: async (root, args: PagingParams): Promise<RecipeProcessConnection> => {
console.log("recipeProcesses", args)
return await readAll(args)
},
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"dev:graphql:explorer": "cd apps/hrea-graphql-explorer && npm start",
"watch": "npm-watch",
"test": "npm-run-all test:unit test:integration",
"t": "TRYORAMA_LOG_LEVEL=debug WASM_LOG=debug RUST_LOG=\"debug,wasmer_compiler_cranelift=error,holochain::core::workflow=error,holochain::conductor::entry_def_store=error\" RUST_BACKTRACE=1 GRAPHQL_DEBUG=1 npx tape test/recipe/test_recipe_flow_crud.js",
"t1": "TRYORAMA_LOG_LEVEL=debug WASM_LOG=debug RUST_LOG=\"debug,wasmer_compiler_cranelift=error,holochain::core::workflow=error,holochain::conductor::entry_def_store=error\" RUST_BACKTRACE=1 GRAPHQL_DEBUG=1 npx tape test/recipe/test_recipe_flow_crud.js",
"t2": "TRYORAMA_LOG_LEVEL=debug WASM_LOG=debug RUST_LOG=warn,debug,wasmer_compiler_cranelift=error,holochain::core::workflow=error,holochain::conductor::entry_def_store=error RUST_BACKTRACE=1 GRAPHQL_DEBUG=1 npx tape test/recipe/test_recipe_process_crud.js",
"test:unit": "scripts/run-unit-tests.sh",
"test:integration": "cd test && npm test",
"clean": "npm-run-all --parallel clean:modules clean:build",
Expand Down
54 changes: 54 additions & 0 deletions test/recipe/test_recipe_flow_crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,60 @@ test('Plan record API', async (t) => {
})
await pause(100)
t.ok(createResp.data.rs.recipeFlow.id, 'recipe created')

const recipeId = createResp.data.rs.recipeFlow.id
const recipeRev = createResp.data.rs.recipeFlow.revisionId
console.log("recipe id", recipeId)

let getResp = await graphQL(`
query($id: ID!) {
res: recipeFlow(id: $id) {
id
revisionId
action {
id
}
note
}
}
`, {
id: recipeId,
})

console.log("get resp", JSON.stringify(getResp.data.res))
console.log("other", JSON.stringify(exampleEntry))

t.ok(getResp, 'recipe read')

t.deepLooseEqual(getResp.data.res, createResp.data.rs.recipeFlow, 'record read OK')

const updateResp = await graphQL(`
mutation($rs: RecipeFlowUpdateParams!) {
res: updateRecipeFlow(recipeFlow: $rs) {
recipeFlow {
id
revisionId
}
}
}
`, {
rs: { revisionId: recipeRev, ...exampleEntry },
})

await pause(100)
t.equal(updateResp.data.res.recipeFlow.id, recipeId, 'record ID consistent')
t.notEqual(updateResp.data.res.recipeFlow.revisionId, recipeRev, 'record updated')

const deleteResult = await graphQL(`
mutation($revisionId: ID!) {
res: deleteRecipeFlow(revisionId: $revisionId)
}
`, {
revisionId: recipeRev,
})
await pause(100)

t.equal(deleteResult.data.res, true, "delete successful")
} catch (e) {
await alice.scenario.cleanUp()
console.log(e)
Expand Down
29 changes: 24 additions & 5 deletions test/recipe/test_recipe_process_crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

test('Plan record API', async (t) => {
console.warn(`\n\n${import.meta.url}`)
const alice = await buildPlayer(['planning', 'specification'])
const alice = await buildPlayer(['recipe', 'specification'])

try {
const { graphQL } = alice
Expand All @@ -33,9 +33,9 @@ test('Plan record API', async (t) => {
const rsId = resp.data.rs.processSpecification.id

const exampleEntry = {
name: "String!",
processClassifiedAs: rsId,
note: "String"
name: "lkasdf",
// processConformsTo: rsId,
note: "fffaa"
}

console.log(exampleEntry)
Expand All @@ -49,7 +49,6 @@ test('Plan record API', async (t) => {
id
revisionId
name
processClassifiedAs
note
}
}
Expand All @@ -59,6 +58,26 @@ test('Plan record API', async (t) => {
})
await pause(100)
t.ok(createResp.data.rs.recipeProcess.id, 'recipe created')
const recipeId = createResp.data.rs.recipeProcess.id
console.log("recipe id", recipeId)

let readResp = await alice.graphQL(`
query($id: ID!) {
res: recipeProcess(id: $id) {
id
revisionId
name
note
}
}
`, {
id: recipeId,
})

console.log("response", JSON.stringify(readResp))

t.ok(readResp, 'recipe read')

} catch (e) {
await alice.scenario.cleanUp()
console.log(e)
Expand Down
4 changes: 2 additions & 2 deletions zomes/rea_recipe_process/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ pub fn construct_response<'a>(
id: address.to_owned(),
revision_id: meta.as_hash().to_owned(),
meta: read_revision_metadata_abbreviated(meta)?,
name: e.note.to_owned(),
image: e.note.to_owned(),
name: e.name.to_owned(),
image: e.image.to_owned(),
note: e.note.to_owned(),
process_conforms_to: e.process_conforms_to.to_owned(),
}
Expand Down
2 changes: 1 addition & 1 deletion zomes/rea_recipe_process/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct ResponseData {
#[derive(Serialize, Deserialize, Debug, SerializedBytes, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CreateRequest {
pub action: ActionId,
// pub action: ActionId,
#[serde(default)]
pub name: MaybeUndefined<String>,
#[serde(default)]
Expand Down
8 changes: 4 additions & 4 deletions zomes/rea_recipe_process/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hdk_records::{
use vf_measurement::QuantityValue;

pub use vf_attributes_hdk::{
ActionId,
// ActionId,
DateTime, FixedOffset,
ExternalURL,
RecipeProcessAddress,
Expand All @@ -30,7 +30,7 @@ pub use vf_attributes_hdk::{
ProcessSpecificationAddress
};

use vf_actions::{ validate_flow_action };
// use vf_actions::{ validate_flow_action };

use hc_zome_rea_recipe_process_rpc::{ CreateRequest, UpdateRequest };

Expand Down Expand Up @@ -113,8 +113,8 @@ impl TryFrom<CreateRequest> for EntryData {

fn try_from(e: CreateRequest) -> RecordAPIResult<EntryData> {
Ok(EntryData {
name: e.note.to_owned().into(),
image: e.note.to_owned().into(),
name: e.name.to_owned().into(),
image: e.image.to_owned().into(),
note: e.note.to_owned().into(),
process_conforms_to: e.process_conforms_to.to_owned().into(),
_nonce: random_bytes(32)?,
Expand Down
1 change: 1 addition & 0 deletions zomes/rea_recipe_process/zome/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ByAddress {

#[hdk_extern]
fn get_recipe_process(ByAddress { address }: ByAddress) -> ExternResult<ResponseData> {
debug!("=====================================get_recipe_process({:?})+++++++++++++++++++++++++++++++++++", address);
Ok(handle_get_recipe_process(address)?)
}

Expand Down

0 comments on commit a6a3476

Please sign in to comment.