Skip to content

Commit

Permalink
(chore) upgrade dependencies (#348)
Browse files Browse the repository at this point in the history
* upgrade dependencies
* node v20 compatibility
  • Loading branch information
konqi authored Feb 27, 2024
1 parent 8fb4edc commit 6d4129f
Show file tree
Hide file tree
Showing 5 changed files with 1,132 additions and 972 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/iron
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"url": "git://github.com/konqi/schematic-kafka.git"
},
"devDependencies": {
"@types/jest": "^29.2.4",
"@types/jest": "^29.5.12",
"@types/kafkajs": "^1.9.0",
"@types/node": "^18.11.15",
"@types/node": "^20.11.20",
"avsc": "^5.7.7",
"jest": "^29.3.1",
"kafkajs": "^2.2.3",
"nock": "^13.2.9",
"node-fetch": "^2.6.7",
"protobufjs": "^7.1.2",
"testcontainers": "^9.1.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"jest": "^29.7.0",
"kafkajs": "^2.2.4",
"nock": "^13.5.4",
"node-fetch": "^3.3.2",
"protobufjs": "^7.2.6",
"testcontainers": "^10.7.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"tslib": "^2.4.1"
Expand Down
20 changes: 10 additions & 10 deletions src/kafka-registry-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SchemaRegistryError, SchemaType } from "./schema-registry-client"
describe("KafkaRegistryHelper with AVRO", () => {
const host = "http://localhost:8081"
const subject = "REGISTRY_TEST_SUBJECT"
let registry: KafkaRegistryHelper = undefined
let registry: KafkaRegistryHelper
const message = { hello: "world" }
const type = Type.forValue(message)
const schema = type.toString()
Expand Down Expand Up @@ -75,15 +75,15 @@ describe("KafkaRegistryHelper with AVRO", () => {
const decodeResult = await registry.decodeWithSubjectAndVersionInformation(encodeResult)
expect(decodeResult.message).toEqual(message)
expect(decodeResult.subjects).toHaveLength(1)
expect(decodeResult.subjects[0].subject).toEqual("🦆")
expect(decodeResult.subjects[0].version).toEqual(42)
expect(decodeResult.subjects!![0].subject).toEqual("🦆")
expect(decodeResult.subjects!![0].version).toEqual(42)
})

it("schema registry return an error other than 404", async () => {
nock(host).post(`/subjects/${subject}`).once().reply(403, "⚠️")

const result = registry.encodeForSubject(subject, message, SchemaType.AVRO, schema)
await expect(result).rejects.toThrowError(new SyntaxError("Unexpected token ⚠ in JSON at position 0"))
await expect(result).rejects.toThrow(SyntaxError)
})

it("use schema from registry / schema not provided for encodeForSubject", async () => {
Expand All @@ -106,7 +106,7 @@ describe("KafkaRegistryHelper with AVRO", () => {
.reply(404, { error_code: 404, message: "don't know this schema" })

const result = registry.encodeForSubject(subject, message)
expect(result).rejects.toThrowError(new SchemaRegistryError(404, "don't know this schema"))
expect(result).rejects.toThrow(new SchemaRegistryError(404, "don't know this schema"))
})

it("missing schema handler for encodeForSubject", async () => {
Expand All @@ -122,7 +122,7 @@ describe("KafkaRegistryHelper with AVRO", () => {
.reply(200, { schema, id: schemaId, schemaType: SchemaType.PROTOBUF })

const result = registry.encodeForSubject(subject, message)
await expect(result).rejects.toThrowError(/Mismatch/)
await expect(result).rejects.toThrow(/Mismatch/)
})

it("encodes for schema id", async () => {
Expand All @@ -146,7 +146,7 @@ describe("KafkaRegistryHelper with AVRO", () => {

const result = registry.encodeForId(schemaId, message)

await expect(result).rejects.toThrowError(/Mismatch/)
await expect(result).rejects.toThrow(/Mismatch/)
})

it("cannot encode for schema id without schemaType handler", async () => {
Expand All @@ -156,7 +156,7 @@ describe("KafkaRegistryHelper with AVRO", () => {

const result = registry.encodeForId(schemaId, message, SchemaType.PROTOBUF)

await expect(result).rejects.toThrowError(/No.*handler.*PROTOBUF/)
await expect(result).rejects.toThrow(/No.*handler.*PROTOBUF/)
})

it("passes through payloads that are not schema encoded", async () => {
Expand All @@ -168,7 +168,7 @@ describe("KafkaRegistryHelper with AVRO", () => {
describe("KafkaRegistryHelper with PROTOBUF", () => {
const host = "http://localhost:8081"
const subject = "REGISTRY_TEST_SUBJECT_PROTOBUF"
let registry: KafkaRegistryHelper = undefined
let registry: KafkaRegistryHelper
const message = { hello: "world" }
const schema = "ADD PROTOBUF SCHEMA HERE"

Expand Down Expand Up @@ -211,7 +211,7 @@ describe("KafkaRegistryHelper with PROTOBUF", () => {
describe("caching logic", () => {
const host = "http://localhost:8081"
const subject = "REGISTRY_TEST_SUBJECT"
let registry: KafkaRegistryHelper = undefined
let registry: KafkaRegistryHelper
const message = { hello: "world" }
const type = Type.forValue(message)
const schema = type.toString()
Expand Down
13 changes: 6 additions & 7 deletions src/schema-registry-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SchemaApiClientConfiguration,
SchemaRegistryClient,
SchemaRegistryError,
SchemaType,
} from "./schema-registry-client"

describe("SchemaRegistryClient (Integration Tests)", () => {
Expand Down Expand Up @@ -35,7 +34,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {
nock("http://test.com").post("/subjects/topic/versions").reply(500, mockError)

const result = schemaApi.registerSchema("topic", schemaPayload)
await expect(result).rejects.toThrowError(new SchemaRegistryError(mockError.error_code, mockError.message))
await expect(result).rejects.toThrow(new SchemaRegistryError(mockError.error_code, mockError.message))
})

it("resolve with schema id if post request returns with 200", async () => {
Expand All @@ -61,7 +60,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {
nock("http://test.com").get("/schemas/ids/1").reply(500, mockError)

const result = schemaApi.getSchemaById(1)
await expect(result).rejects.toThrowError(new SchemaRegistryError(mockError.error_code, mockError.message))
await expect(result).rejects.toThrow(new SchemaRegistryError(mockError.error_code, mockError.message))
})

it("resolve with schema if get request returns with 200", async () => {
Expand Down Expand Up @@ -214,7 +213,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {

const result = schemaApi.checkSchema(subject, { schema: fakeSchema.schema })

await expect(result).rejects.toThrowError(new SchemaRegistryError(404, "Nope"))
await expect(result).rejects.toThrow(new SchemaRegistryError(404, "Nope"))
})

it("responds with empty response body", async () => {
Expand All @@ -223,7 +222,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {

const result = schemaApi.checkSchema(subject, { schema: fakeSchema.schema })

await expect(result).rejects.toThrowError(new Error("Invalid schema registry response"))
await expect(result).rejects.toThrow(new Error("Invalid schema registry response"))
})

it("responds with invalid response body", async () => {
Expand All @@ -232,7 +231,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {

const result = schemaApi.checkSchema(subject, { schema: fakeSchema.schema })

await expect(result).rejects.toThrowError(new SyntaxError("Unexpected token o in JSON at position 1"))
await expect(result).rejects.toThrow(SyntaxError)
})
})

Expand All @@ -250,7 +249,7 @@ describe("SchemaRegistryClient (Integration Tests)", () => {
nock("http://test.com").get("/subjects/topic/versions/latest").reply(500, mockError)

const result = schemaApi.getLatestVersionForSubject("topic")
await expect(result).rejects.toThrowError(new SchemaRegistryError(mockError.error_code, mockError.message))
await expect(result).rejects.toThrow(new SchemaRegistryError(mockError.error_code, mockError.message))
})

it("resolve with schema and id if both get requests return with 200", async () => {
Expand Down
Loading

0 comments on commit 6d4129f

Please sign in to comment.