Skip to content

Commit

Permalink
Make sure that the functions are not been called at the start of the …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
coskucinkilic committed Oct 1, 2024
1 parent 8873ef0 commit b4dad74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions frontend/src/tests/lib/api/governance.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@ describe("neurons-api", () => {
const visibility = NeuronVisibility.Public;

it("changes visibility for multiple neurons", async () => {
expect(mockGovernanceCanister.setVisibility).not.toHaveBeenCalled();

mockGovernanceCanister.setVisibility.mockResolvedValue(undefined);

await changeNeuronVisibility({
Expand All @@ -759,6 +761,8 @@ describe("neurons-api", () => {
});

it("throws error when changing visibility fails", async () => {
expect(mockGovernanceCanister.setVisibility).not.toHaveBeenCalled();

const error = new Error("Visibility change failed");
mockGovernanceCanister.setVisibility.mockRejectedValue(error);

Expand Down
13 changes: 12 additions & 1 deletion frontend/src/tests/lib/services/neurons.services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,10 @@ describe("neurons-services", () => {
});

describe("changeNeuronVisibility", () => {
it("should change visibility to public for all neurons", async () => {
it("should call changeNeuronVisibility and getNeuron", async () => {
expect(spyChangeNeuronVisibility).not.toHaveBeenCalled();
expect(spyGetNeuron).not.toHaveBeenCalled();

neuronsStore.setNeurons({ neurons: [controlledNeuron], certified: true });

const { success } = await changeNeuronVisibility({
Expand All @@ -1882,6 +1885,8 @@ describe("neurons-services", () => {
});

it("should change visibility to private for all neurons", async () => {
expect(spyChangeNeuronVisibility).not.toHaveBeenCalled();
expect(spyGetNeuron).not.toHaveBeenCalled();
neuronsStore.setNeurons({ neurons: [controlledNeuron], certified: true });

const { success } = await changeNeuronVisibility({
Expand All @@ -1900,6 +1905,8 @@ describe("neurons-services", () => {
});

it("should handle partial failure", async () => {
expect(spyChangeNeuronVisibility).not.toHaveBeenCalled();
expect(spyGetNeuron).not.toHaveBeenCalled();
const neuron1 = { ...controlledNeuron, neuronId: 1n };
const neuron2 = { ...controlledNeuron, neuronId: 2n };
neuronsStore.setNeurons({ neurons: [neuron1, neuron2], certified: true });
Expand All @@ -1921,6 +1928,8 @@ describe("neurons-services", () => {
});

it("should handle complete failure", async () => {
expect(spyChangeNeuronVisibility).not.toHaveBeenCalled();
expect(spyGetNeuron).not.toHaveBeenCalled();
neuronsStore.setNeurons({ neurons: [controlledNeuron], certified: true });
spyChangeNeuronVisibility.mockRejectedValue(new Error("Test error"));

Expand All @@ -1938,6 +1947,8 @@ describe("neurons-services", () => {
});

it("should handle multiple neurons", async () => {
expect(spyChangeNeuronVisibility).not.toHaveBeenCalled();
expect(spyGetNeuron).not.toHaveBeenCalled();
const neuron1 = { ...controlledNeuron, neuronId: 1n };
const neuron2 = { ...controlledNeuron, neuronId: 2n };
neuronsStore.setNeurons({ neurons: [neuron1, neuron2], certified: true });
Expand Down

0 comments on commit b4dad74

Please sign in to comment.