Skip to content

Commit

Permalink
Add and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coskucinkilic committed Oct 10, 2024
1 parent 7162ecf commit 9573096
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions packages/nns/src/governance.canister.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,27 +708,70 @@ describe("GovernanceCanister", () => {
});

describe("GovernanceCanister.getNeuron", () => {
it("should fetch and convert a neuron", async () => {
it("should fetch and convert a neuron using old service", async () => {
const service = mock<ActorSubclass<GovernanceService>>();
const certifiedService = mock<ActorSubclass<GovernanceService>>();
const oldService = mock<ActorSubclass<GovernanceService>>();
oldService.list_neurons.mockResolvedValue(mockListNeuronsResponse);
const neuronId = BigInt(1);

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
certifiedServiceOverride: certifiedService,
serviceOverride: service,
oldListNeuronsServiceOverride: service,
oldListNeuronsServiceOverride: oldService,
});

service.list_neurons.mockResolvedValue(
Promise.resolve(mockListNeuronsResponse),
);

const response = await governance.getNeuron({
certified: true,
neuronId: BigInt(1),
neuronId: neuronId,
});

expect(service.list_neurons).toBeCalled();
expect(oldService.list_neurons).toBeCalledWith({
neuron_ids: new BigUint64Array([neuronId]),
include_neurons_readable_by_caller: false,
include_empty_neurons_readable_by_caller: [],
include_public_neurons_in_full_neurons: [],
});

expect(certifiedService.list_neurons).not.toBeCalled();
expect(response).not.toBeUndefined();
expect(response?.state).toEqual(mockNeuronInfo.state);
expect(Number(response?.neuronId)).toEqual(Number(mockNeuronId));
expect(service.list_neurons).not.toBeCalled();
expect(oldService.list_neurons).toBeCalledTimes(1);
});
it("should fetch and convert a neuron with new service when includeEmptyNeurons is set to true", async () => {
const service = mock<ActorSubclass<GovernanceService>>();
const certifiedService = mock<ActorSubclass<GovernanceService>>();
const oldService = mock<ActorSubclass<GovernanceService>>();
certifiedService.list_neurons.mockResolvedValue(mockListNeuronsResponse);
const neuronId = BigInt(1);

const governance = GovernanceCanister.create({
certifiedServiceOverride: certifiedService,
serviceOverride: service,
oldListNeuronsServiceOverride: oldService,
});

const response = await governance.getNeuron({
certified: true,
neuronId,
includeEmptyNeurons: true,
});

expect(certifiedService.list_neurons).toBeCalledWith({
neuron_ids: new BigUint64Array([neuronId]),
include_neurons_readable_by_caller: false,
include_empty_neurons_readable_by_caller: [true],
include_public_neurons_in_full_neurons: [],
});

expect(certifiedService.list_neurons).toBeCalledTimes(1);
expect(response).not.toBeUndefined();
expect(response?.state).toEqual(mockNeuronInfo.state);
expect(Number(response?.neuronId)).toEqual(Number(mockNeuronId));
expect(service.list_neurons).not.toBeCalled();
expect(oldService.list_neurons).not.toBeCalled();
});
});

Expand Down

0 comments on commit 9573096

Please sign in to comment.