Skip to content

Commit

Permalink
Fix some instances of follow in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harlan T Wood committed May 21, 2023
1 parent 168c474 commit 6e899e3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 101 deletions.
1 change: 1 addition & 0 deletions tests/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const createAgents = async (scenario) => {
return playersWithApps.map((player) => {
return {
agentPubKey: player.agentPubKey,
cells: player.cells, // so that legacy calls to cells[0] still work
follow: (payload: FollowInput): Promise<null> =>
player.cells[0].callZome({
zome_name: "follows",
Expand Down
37 changes: 10 additions & 27 deletions tests/src/mewsfeed/follows/follower-to-creators.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { assert, test, expect } from "vitest";
import { runScenario, pause } from "@holochain/tryorama";
import { Record } from "@holochain/client";
import { mewsfeedAppBundleSource } from "../../common";
import { createAgents } from "../../common";

test("link a Follower to a Creator", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob] = await scenario.addPlayersWithApps([
appSource,
appSource,
]);
const [alice, bob] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -94,22 +88,18 @@ test("link a Follower to a Creator", async () => {
test("Agent cannot follow themselves", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice] = await scenario.addPlayersWithApps([appSource]);
const [alice] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
await scenario.shareAllAgents();

// Alice tries to follow herself
const response = alice.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: alice.agentPubKey,
const response = alice.follow({
agent: alice.agentPubKey,
follow_topics: [],
});
await expect(response).rejects.toHaveProperty(
"data.data",
Expand All @@ -124,15 +114,9 @@ test("Agent cannot follow themselves", async () => {
test("Agent can only change their own follows", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob] = await scenario.addPlayersWithApps([
appSource,
appSource,
]);
const [alice, bob] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand All @@ -142,10 +126,9 @@ test("Agent can only change their own follows", async () => {
const targetAddress = bob.agentPubKey;

// Alice follows bob
await alice.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: targetAddress,
await alice.follow({
agent: targetAddress,
follow_topics: [],
});

await pause(1200);
Expand Down
102 changes: 28 additions & 74 deletions tests/src/mewsfeed/mews/followed-creators-mews.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ import { runScenario, pause } from "@holochain/tryorama";
import { Record } from "@holochain/client";
import { createMew } from "./common";
import { FeedMew, Mew, MewTypeName } from "../../../../ui/src/types/types";
import { mewsfeedAppBundleSource } from "../../common";
import { createAgents } from "../../common";

test("create a Mew and get followed creators mews", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob] = await scenario.addPlayersWithApps([
appSource,
appSource,
]);
// Add 2 players with the test app to the Scenario.
const [alice, bob] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -53,15 +46,8 @@ test("create a Mew and get followed creators mews", async () => {
test("Followed creators mews should include mews of followed creator", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob] = await scenario.addPlayersWithApps([
appSource,
appSource,
]);
// Add 2 players with the test app to the Scenario.
const [alice, bob] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -89,10 +75,9 @@ test("Followed creators mews should include mews of followed creator", async ()
"bob's mews feed is initially empty"
);

await bob.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: alice.agentPubKey,
await bob.follow({
agent: alice.agentPubKey,
follow_topics: [],
});

const bobMewsFeed: FeedMew[] = await bob.cells[0].callZome({
Expand All @@ -115,12 +100,8 @@ test("Followed creators mews should include mews of followed creator", async ()
test("Followed creators mews should include own mews", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice] = await scenario.addPlayersWithApps([appSource]);
// Add 2 players with the test app to the Scenario.
const [alice] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -171,16 +152,8 @@ test("Followed creators mews should include own mews", async () => {
test("Followed creators mews should not include mews of non-followed creator", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob, carol] = await scenario.addPlayersWithApps([
appSource,
appSource,
appSource,
]);
// Add 2 players with the test app to the Scenario.
const [alice, bob, carol] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -210,10 +183,9 @@ test("Followed creators mews should not include mews of non-followed creator", a
payload: carolMewInput,
});

await bob.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: alice.agentPubKey,
await bob.follow({
agent: alice.agentPubKey,
follow_topics: [],
});
await pause(1000);

Expand All @@ -237,15 +209,8 @@ test("Followed creators mews should not include mews of non-followed creator", a
test("Unfollowing should exclude creators mews from feed", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob] = await scenario.addPlayersWithApps([
appSource,
appSource,
]);
// Add 2 players with the test app to the Scenario.
const [alice, bob] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand All @@ -263,10 +228,9 @@ test("Unfollowing should exclude creators mews from feed", async () => {
payload: aliceMewInput,
});

await bob.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: alice.agentPubKey,
await bob.follow({
agent: alice.agentPubKey,
follow_topics: [],
});
await pause(1000);

Expand Down Expand Up @@ -306,16 +270,8 @@ test("Unfollowing should exclude creators mews from feed", async () => {
test("Followed creators mews should be ordered by timestamp in descending order", async () => {
await runScenario(
async (scenario) => {
// Set up the app to be installed
const appSource = { appBundleSource: mewsfeedAppBundleSource };

// Add 2 players with the test app to the Scenario. The returned players
// can be destructured.
const [alice, bob, carol] = await scenario.addPlayersWithApps([
appSource,
appSource,
appSource,
]);
// Add 2 players with the test app to the Scenario.
const [ann, bob, cat] = await createAgents(scenario);

// Shortcut peer discovery through gossip and register all agents in every
// conductor of the scenario.
Expand Down Expand Up @@ -369,15 +325,13 @@ test("Followed creators mews should be ordered by timestamp in descending order"
payload: fourthMewInput,
});
// alice starts following bob and carol
await alice.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: bob.agentPubKey,
await alice.follow({
agent: bob.agentPubKey,
follow_topics: [],
});
await alice.cells[0].callZome({
zome_name: "follows",
fn_name: "follow",
payload: carol.agentPubKey,
await alice.follow({
agent: carol.agentPubKey,
follow_topics: [],
});

await pause(1000);
Expand Down

0 comments on commit 6e899e3

Please sign in to comment.