Skip to content

Commit

Permalink
fix(request): only require type passed in through options on update
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Mar 2, 2024
1 parent e589845 commit bbed64f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
pull_request:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use pnpm 8.x
uses: pnpm/action-setup@v2
with:
version: 8

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install

- name: Biome CI
run: pnpm exec biome ci .

- name: Test
run: pnpm test

- name: Type Check
run: pnpm exec tsc --noEmit
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Biome CI
run: pnpm exec biome ci .

- name: Test
run: pnpm test

- name: Build
run: pnpm build

Expand Down
4 changes: 2 additions & 2 deletions src/accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type AcceptMediaType = {
acceptExt: Record<string, string>;
};

type Accept = AcceptMediaType[];
export type Accept = AcceptMediaType[];

const asciiRange = (start: number, end: number): string => {
let chars = "";
Expand All @@ -30,7 +30,7 @@ const QCHAR = `\t ${VCHAR} ${OBS_TEXT}`;

type RawParameter = [string, string];

class AcceptParser {
export class AcceptParser {
private static readonly default: AcceptMediaType = {
type: "*",
subType: "*",
Expand Down
4 changes: 1 addition & 3 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ export const parseCreateRequest = <
};

export type ParseUpdateRequestOptions<
TId extends string,
TType extends string,
TAttributesSchema extends z.SomeZodObject,
TRelationshipsSchema extends z.SomeZodObject | undefined,
Expand All @@ -262,9 +261,8 @@ export const parseUpdateRequest = <
TRelationshipsSchema extends z.SomeZodObject | undefined,
>(
id: TId,
type: TType,
koaContext: Context,
options: ParseUpdateRequestOptions<TId, TType, TAttributesSchema, TRelationshipsSchema>,
options: ParseUpdateRequestOptions<TType, TAttributesSchema, TRelationshipsSchema>,
): ParseUpdateRequestResult<TId, TType, TAttributesSchema, TRelationshipsSchema> => {
return parseDataRequest(fixedIdSchema(id), koaContext, options);
};
Expand Down
9 changes: 5 additions & 4 deletions test/headers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, expect, it } from "vitest";
import { type Accept, parseAccept } from "../src/headers.js";
import { AcceptParser } from "../src/accept.js";
import type { Accept } from "../src/accept.js";

describe("parseAccept", () => {
describe("AcceptParser", () => {
const validHeaders: [string, string, Accept][] = [
["empty", " \t ", [{ type: "*", subType: "*", parameters: {}, weight: 1, acceptExt: {} }]],
[
Expand Down Expand Up @@ -126,7 +127,7 @@ describe("parseAccept", () => {

for (const [name, header, expected] of validHeaders) {
it(`should match ${name}`, () => {
const actual = parseAccept(header);
const actual = AcceptParser.parse(header);
expect(actual).toEqual(expected);
});
}
Expand All @@ -153,7 +154,7 @@ describe("parseAccept", () => {

for (const [name, header, expectedMessage] of invalidHeaders) {
it(`should throw error on ${name}`, () => {
expect(() => parseAccept(header)).toThrow(expectedMessage);
expect(() => AcceptParser.parse(header)).toThrow(expectedMessage);
});
}
});

0 comments on commit bbed64f

Please sign in to comment.