Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-mice-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baseplate-dev/fastify-generators': patch
---

Fix handling of data operations with falsy update values
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default async function setup(): Promise<void> {
export default function setup(): void {
// Set Redis key prefix for test isolation
process.env.REDIS_KEY_PREFIX = 'test:';
console.info('Redis key prefix set to "test:" for isolation');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -171,7 +171,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
3 changes: 2 additions & 1 deletion tests/simple/apps/backend/baseplate/file-id-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@baseplate-dev/core-generators#node/prettier:prettier-ignore": ".prettierignore",
"@baseplate-dev/core-generators#node/ts-utils:string": "src/utils/string.ts",
"@baseplate-dev/core-generators#node/typescript:tsconfig": "tsconfig.json",
"@baseplate-dev/core-generators#node/vitest:global-setup": "src/tests/scripts/global-setup.ts",
"@baseplate-dev/core-generators#node/vitest:global-setup-env": "src/tests/scripts/global-setup-env.ts",
"@baseplate-dev/core-generators#node/vitest:logger-test-helper": "src/tests/helpers/logger.test-helper.ts",
"@baseplate-dev/core-generators#node/vitest:vitest-config": "vitest.config.ts",
"@baseplate-dev/fastify-generators#core/app-module-setup:app-modules": "src/utils/app-modules.ts",
Expand Down Expand Up @@ -60,6 +60,7 @@
"@baseplate-dev/fastify-generators#prisma/prisma:seed": "src/prisma/seed.ts",
"@baseplate-dev/fastify-generators#prisma/prisma:service": "src/services/prisma.ts",
"@baseplate-dev/fastify-generators#vitest/prisma-vitest:db-test-helper": "src/tests/helpers/db.test-helper.ts",
"@baseplate-dev/fastify-generators#vitest/prisma-vitest:global-setup-prisma": "src/tests/scripts/global-setup-prisma.ts",
"@baseplate-dev/fastify-generators#vitest/prisma-vitest:prisma-test-helper": "src/tests/helpers/prisma.test-helper.ts",
"@baseplate-dev/fastify-generators#yoga/yoga-plugin:graphql-plugin": "src/plugins/graphql/index.ts",
"@baseplate-dev/fastify-generators#yoga/yoga-plugin:use-graph-logger": "src/plugins/graphql/use-graph-logger.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { loadEnvFile } from 'node:process';

loadEnvFile('.env');

export default async function setup(): Promise<void> {
// Environment loaded
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { loadEnvFile } from 'node:process';

import { createTestDatabase } from '../helpers/db.test-helper.js';

loadEnvFile('.env');

export default async function setup(): Promise<void> {
const { TEST_MODE } = process.env;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export default defineConfig({
plugins: [tsconfigPaths()],
test: {
clearMocks: true,
globalSetup: './tests/scripts/global-setup.ts',
globalSetup: [
'./tests/scripts/global-setup-env.ts',
'./tests/scripts/global-setup-prisma.ts',
],
maxWorkers: 1,
passWithNoTests: true,
root: './src',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { loadEnvFile } from 'node:process';

loadEnvFile('.env');

export default async function setup(): Promise<void> {
// Environment loaded
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { loadEnvFile } from 'node:process';

import { createTestDatabase } from '../helpers/db.test-helper.js';

loadEnvFile('.env');

export default async function setup(): Promise<void> {
const { TEST_MODE } = process.env;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function transformFields<
loadExisting,
});

if (result.data) {
if (result.data !== undefined) {
data[fieldKey as keyof TFields] = result.data as FieldDataOrFunction<
TFields[keyof TFields]
>;
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function transformFields<
create[key as keyof TFields] =
value.create as InferFieldsCreateOutput<TFields>[keyof TFields];
}
if (value.update) {
if (value.update !== undefined) {
update[key as keyof TFields] =
value.update as InferFieldsUpdateOutput<TFields>[keyof TFields];
}
Expand Down
5 changes: 4 additions & 1 deletion tests/simple/apps/backend/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export default defineConfig({
plugins: [tsconfigPaths()],
test: {
clearMocks: true,
globalSetup: './tests/scripts/global-setup.ts',
globalSetup: [
'./tests/scripts/global-setup-env.ts',
'./tests/scripts/global-setup-prisma.ts',
],
maxWorkers: 1,
passWithNoTests: true,
root: './src',
Expand Down