Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
penpenpng committed Dec 3, 2023
1 parent 3362d96 commit d87466a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
64 changes: 60 additions & 4 deletions src/__test__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,73 @@ export const faker = {
}
>
): EventPacket {
const message: Nostr.ToClientMessage.EVENT = [
"EVENT",
packetOrEvent?.subId ?? "*",
faker.event(packetOrEvent?.event ?? packetOrEvent),
];

return {
from: packetOrEvent?.from ?? "*",
subId: packetOrEvent?.subId ?? "*",
event: faker.event(packetOrEvent?.event ?? packetOrEvent),
message,
type: "EVENT",
};
},
messagePacket(message: Nostr.ToClientMessage.Any): MessagePacket {
return {
from: "*",
message,
};
const from = "*";
const type = message[0];

switch (type) {
case "EVENT":
return {
from,
type,
message,
subId: message[1],
event: message[2],
};
case "EOSE":
return {
from,
type,
message,
subId: message[1],
};
case "OK":
return {
from,
type,
message,
eventId: message[1],
id: message[1],
ok: message[2],
notice: message[3],
};
case "NOTICE":
return {
from,
type,
message,
notice: message[1],
};
case "AUTH":
return {
from,
type,
message,
challengeMessage: message[1],
};
case "COUNT":
return {
from,
type,
message,
subId: message[1],
count: message[2],
};
}
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/__test__/keep-alive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { createMockRelay, type MockRelay } from "vitest-nostr";

import { createRxForwardReq, createRxNostr, RxNostr } from "../index.js";
import { disposeMockRelay, faker, spyEvent, stateWillBe } from "./helper.js";
import { disposeMockRelay, faker, stateWillBe } from "./helper.js";

describe("", () => {
const DEFAULT_RELAY = "ws://localhost:1234";
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/operator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ test("tie()", async () => {
}))
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
expectObservable(packet$).toEqual(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
of<any[]>(
{
...packets[0],
Expand Down
4 changes: 1 addition & 3 deletions src/rx-nostr/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { filter, type OperatorFunction } from "rxjs";

import type { LazyFilter, LazyREQ, MessagePacket } from "../packet.js";
import type { LazyFilter, LazyREQ } from "../packet.js";
import type { RxReq } from "../req.js";
import type {
AcceptableDefaultRelaysConfig,
Expand Down

0 comments on commit d87466a

Please sign in to comment.