Browse Source

Merge branch 'develop' into refactor/timezone-locale

pull/5719/head
Wing-Kam Wong 2 years ago
parent
commit
7705716af1
  1. 10540
      package-lock.json
  2. 50
      packages/nc-gui/components/cell/DateTimePicker.vue
  3. 7
      packages/nc-gui/components/smartsheet/Cell.vue
  4. 6
      packages/nc-gui/components/smartsheet/Grid.vue
  5. 6
      packages/nc-gui/components/virtual-cell/Formula.vue
  6. 4
      packages/nc-gui/components/virtual-cell/components/ItemChip.vue
  7. 4
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  8. 4
      packages/nc-gui/components/virtual-cell/components/ListItems.vue
  9. 3
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  10. 48
      packages/nc-gui/composables/useMultiSelect/index.ts
  11. 2
      packages/nc-gui/lib/types.ts
  12. 2
      packages/nc-gui/package-lock.json
  13. 2
      packages/nc-gui/plugins/a.dayjs.ts
  14. 7
      packages/nc-gui/store/project.ts
  15. 26
      packages/nc-gui/utils/cell.ts
  16. 8
      packages/nc-gui/utils/dateTimeUtils.ts
  17. 1
      packages/nc-gui/utils/index.ts
  18. 2
      packages/nc-lib-gui/package.json
  19. 4
      packages/nocodb-sdk/package-lock.json
  20. 2
      packages/nocodb-sdk/package.json
  21. 2
      packages/nocodb-sdk/src/lib/Api.ts
  22. 20
      packages/nocodb/package-lock.json
  23. 6
      packages/nocodb/package.json
  24. 69
      packages/nocodb/src/Noco.ts
  25. 51
      packages/nocodb/src/app.module.ts
  26. 214
      packages/nocodb/src/db/BaseModelSqlv2.ts
  27. 14
      packages/nocodb/src/db/CustomKnex.ts
  28. 30
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
  29. 34
      packages/nocodb/src/meta/meta.service.ts
  30. 63
      packages/nocodb/src/models/Model.ts
  31. 20
      packages/nocodb/src/modules/global/global.module.ts
  32. 19
      packages/nocodb/src/services/app-init.service.spec.ts
  33. 68
      packages/nocodb/src/services/app-init.service.ts
  34. 10
      packages/nocodb/src/utils/NcConfigFactory.ts
  35. 51
      packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts
  36. 205
      packages/nocodb/tests/unit/rest/tests/tableRow.test.ts
  37. 4704
      tests/playwright/package-lock.json
  38. 3
      tests/playwright/package.json
  39. 9
      tests/playwright/pages/Dashboard/ExpandedForm/index.ts
  40. 24
      tests/playwright/pages/Dashboard/TreeView.ts
  41. 29
      tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts
  42. 14
      tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts
  43. 8
      tests/playwright/pages/Dashboard/common/Cell/index.ts
  44. 1
      tests/playwright/pages/Dashboard/common/Toolbar/index.ts
  45. 950
      tests/playwright/tests/db/timezone.spec.ts
  46. 4
      tests/playwright/tests/db/undo-redo.spec.ts
  47. 2
      tests/playwright/tests/db/viewGridShare.spec.ts
  48. 48
      tests/playwright/tests/utils/config.ts

10540
package-lock.json generated

File diff suppressed because it is too large Load Diff

50
packages/nc-gui/components/cell/DateTimePicker.vue

@ -18,14 +18,13 @@ import {
interface Props {
modelValue?: string | null
isPk?: boolean
isUpdatedFromCopyNPaste: Record<string, boolean>
}
const { modelValue, isPk, isUpdatedFromCopyNPaste } = defineProps<Props>()
const { modelValue, isPk } = defineProps<Props>()
const emit = defineEmits(['update:modelValue'])
const { isMssql, isMysql, isXcdbBase } = useProject()
const { isMysql } = useProject()
const { showNull } = useGlobal()
@ -45,8 +44,6 @@ const dateTimeFormat = $computed(() => {
return `${dateFormat} ${timeFormat}`
})
let localModelValue = modelValue ? dayjs(modelValue).utc().local() : undefined
let localState = $computed({
get() {
if (!modelValue) {
@ -58,45 +55,7 @@ let localState = $computed({
return undefined
}
const isXcDB = isXcdbBase(column.value.base_id)
// cater copy and paste
// when copying a datetime cell, the copied value would be local time
// when pasting a datetime cell, UTC (xcdb) will be saved in DB
// we convert back to local time
if (column.value.title! in (isUpdatedFromCopyNPaste ?? {})) {
localModelValue = dayjs(modelValue).utc().local()
return localModelValue
}
// ext db
if (!isXcDB) {
return /^\d+$/.test(modelValue) ? dayjs(+modelValue) : dayjs(modelValue)
}
if (isMssql(column.value.base_id)) {
// e.g. 2023-04-29T11:41:53.000Z
return dayjs(modelValue)
}
// if cdf is defined, that means the value is auto-generated
// hence, show the local time
if (column?.value?.cdf) {
return dayjs(modelValue).utc().local()
}
// if localModelValue is defined, show localModelValue instead
// localModelValue is set in setter below
if (localModelValue) {
const res = localModelValue
// resetting localModelValue here
// e.g. save in expanded form -> render the correct modelValue
localModelValue = undefined
return res
}
// empty cell - use modelValue in local time
return dayjs(modelValue).utc().local()
},
set(val?: dayjs.Dayjs) {
if (!val) {
@ -105,10 +64,7 @@ let localState = $computed({
}
if (val.isValid()) {
const formattedValue = dayjs(val?.format(isMysql(column.value.base_id) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ'))
// setting localModelValue to cater NOW function in date picker
localModelValue = formattedValue
emit('update:modelValue', formattedValue)
emit('update:modelValue', val?.format(isMysql(column.value.base_id) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ'))
}
},
})

7
packages/nc-gui/components/smartsheet/Cell.vue

@ -209,12 +209,7 @@ onUnmounted(() => {
<LazyCellMultiSelect v-else-if="isMultiSelect(column)" v-model="vModel" :row-index="props.rowIndex" />
<LazyCellDatePicker v-else-if="isDate(column, abstractType)" v-model="vModel" :is-pk="isPrimaryKey(column)" />
<LazyCellYearPicker v-else-if="isYear(column, abstractType)" v-model="vModel" :is-pk="isPrimaryKey(column)" />
<LazyCellDateTimePicker
v-else-if="isDateTime(column, abstractType)"
v-model="vModel"
:is-pk="isPrimaryKey(column)"
:is-updated-from-copy-n-paste="currentRow.rowMeta.isUpdatedFromCopyNPaste"
/>
<LazyCellDateTimePicker v-else-if="isDateTime(column, abstractType)" v-model="vModel" :is-pk="isPrimaryKey(column)" />
<LazyCellTimePicker v-else-if="isTime(column, abstractType)" v-model="vModel" :is-pk="isPrimaryKey(column)" />
<LazyCellRating v-else-if="isRating(column)" v-model="vModel" />
<LazyCellDuration v-else-if="isDuration(column)" v-model="vModel" />

6
packages/nc-gui/components/smartsheet/Grid.vue

@ -316,12 +316,6 @@ const {
return
}
// See DateTimePicker.vue for details
data.value[ctx.row].rowMeta.isUpdatedFromCopyNPaste = {
...data.value[ctx.row].rowMeta.isUpdatedFromCopyNPaste,
[ctx.updatedColumnTitle || columnObj.title]: true,
}
// update/save cell value
await updateOrSaveRow(rowObj, ctx.updatedColumnTitle || columnObj.title)
},

6
packages/nc-gui/components/virtual-cell/Formula.vue

@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { ColumnType } from 'nocodb-sdk'
import type { Ref } from 'vue'
import { CellValueInj, ColumnInj, computed, handleTZ, inject, renderValue, replaceUrlsWithLink, useProject } from '#imports'
import { CellValueInj, ColumnInj, computed, handleTZ, inject, replaceUrlsWithLink, useProject } from '#imports'
// todo: column type doesn't have required property `error` - throws in typecheck
const column = inject(ColumnInj) as Ref<ColumnType & { colOptions: { error: any } }>
@ -10,9 +10,7 @@ const cellValue = inject(CellValueInj)
const { isPg } = useProject()
const result = computed(() =>
isPg(column.value.base_id) ? renderValue(handleTZ(cellValue?.value)) : renderValue(cellValue?.value),
)
const result = computed(() => (isPg(column.value.base_id) ? handleTZ(cellValue?.value) : cellValue?.value))
const urls = computed(() => replaceUrlsWithLink(result.value))

4
packages/nc-gui/components/virtual-cell/components/ItemChip.vue

@ -7,9 +7,9 @@ import {
iconMap,
inject,
ref,
renderValue,
useExpandedFormDetached,
useLTARStoreOrThrow,
useUIPermission,
} from '#imports'
interface Props {
@ -60,7 +60,7 @@ export default {
:class="{ active }"
@click="openExpandedForm"
>
<span class="name">{{ renderValue(value) }}</span>
<span class="name">{{ value }}</span>
<div v-show="active || isForm" v-if="!readOnly && !isLocked && isUIAllowed('xcDatatableEditable')" class="flex items-center">
<component

4
packages/nc-gui/components/virtual-cell/components/ListChildItems.vue

@ -13,10 +13,10 @@ import {
iconMap,
inject,
ref,
renderValue,
useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow,
useVModel,
watch,
} from '#imports'
const props = defineProps<{ modelValue?: boolean; cellValue: any }>()
@ -148,7 +148,7 @@ const onClick = (row: Row) => {
>
<div class="flex items-center">
<div class="flex-1 overflow-hidden min-w-0">
{{ renderValue(row[relatedTableDisplayValueProp]) }}
{{ row[relatedTableDisplayValueProp] }}
<span class="text-gray-400 text-[11px] ml-1">(Primary key : {{ getRelatedTableRowId(row) }})</span>
</div>

4
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -12,11 +12,11 @@ import {
inject,
isDrawerExist,
ref,
renderValue,
useLTARStoreOrThrow,
useSelectedCellKeyupListener,
useSmartsheetRowStoreOrThrow,
useVModel,
watch,
} from '#imports'
const props = defineProps<{ modelValue: boolean }>()
@ -229,7 +229,7 @@ watch(vModel, (nextVal) => {
:class="{ 'nc-selected-row': selectedRowIndex === i }"
@click="linkRow(refRow)"
>
{{ renderValue(refRow[relatedTableDisplayValueProp]) }}
{{ refRow[relatedTableDisplayValueProp] }}
<span class="hidden group-hover:(inline) text-gray-400 text-[11px] ml-1">
({{ $t('labels.primaryKey') }} : {{ getRelatedTableRowId(refRow) }})
</span>

3
packages/nc-gui/composables/useMultiSelect/convertCellData.ts

@ -7,7 +7,6 @@ import { parseProp } from '#imports'
export default function convertCellData(
args: { from: UITypes; to: UITypes; value: any; column: ColumnType; appInfo: AppInfo },
isMysql = false,
isXcdbBase = false,
) {
const { from, to, value } = args
if (from === to && ![UITypes.Attachment, UITypes.Date, UITypes.DateTime, UITypes.Time, UITypes.Year].includes(to)) {
@ -43,7 +42,7 @@ export default function convertCellData(
if (!parsedDateTime.isValid()) {
throw new Error('Not a valid datetime value')
}
return parsedDateTime.format('YYYY-MM-DD HH:mm:ssZ')
return parsedDateTime.format(dateFormat)
}
case UITypes.Time: {
let parsedTime = dayjs(value)

48
packages/nc-gui/composables/useMultiSelect/index.ts

@ -1,4 +1,3 @@
import dayjs from 'dayjs'
import type { MaybeRef } from '@vueuse/core'
import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
@ -8,7 +7,6 @@ import convertCellData from './convertCellData'
import type { Nullable, Row } from '~/lib'
import {
copyTable,
dateFormats,
extractPkFromRow,
extractSdkResponseErrorMsg,
isMac,
@ -16,7 +14,6 @@ import {
message,
reactive,
ref,
timeFormats,
unref,
useCopy,
useEventListener,
@ -55,7 +52,7 @@ export function useMultiSelect(
const { appInfo } = useGlobal()
const { isMysql, isXcdbBase } = useProject()
const { isMysql } = useProject()
let clipboardContext = $ref<{ value: any; uidt: UITypes } | null>(null)
@ -82,12 +79,6 @@ export function useMultiSelect(
activeCell.col = col
}
function constructDateTimeFormat(column: ColumnType) {
const dateFormat = parseProp(column?.meta)?.date_format ?? dateFormats[0]
const timeFormat = parseProp(column?.meta)?.time_format ?? timeFormats[0]
return `${dateFormat} ${timeFormat}`
}
async function copyValue(ctx?: Cell) {
try {
if (selectedRange.start !== null && selectedRange.end !== null && !selectedRange.isSingleCell()) {
@ -115,41 +106,6 @@ export function useMultiSelect(
if (typeof textToCopy === 'object') {
textToCopy = JSON.stringify(textToCopy)
}
if (columnObj.uidt === UITypes.Formula) {
textToCopy = textToCopy.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\b/g, (d: string) => {
// TODO(timezone): retrieve the format from the corresponding column meta
// assume hh:mm at this moment
return dayjs(d).utc().local().format('YYYY-MM-DD HH:mm')
})
}
if (columnObj.uidt === UITypes.DateTime) {
// remove `"`
// e.g. "2023-05-12T08:03:53.000Z" -> 2023-05-12T08:03:53.000Z
textToCopy = textToCopy.replace(/["']/g, '')
const isMySQL = isMysql(columnObj.base_id)
let d = dayjs(textToCopy)
if (!d.isValid()) {
// insert a datetime value, copy the value without refreshing
// e.g. textToCopy = 2023-05-12T03:49:25.000Z
// feed custom parse format
d = dayjs(textToCopy, isMySQL ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ')
}
// users can change the datetime format in UI
// `textToCopy` would be always in YYYY-MM-DD HH:mm:ss(Z / +xx:yy) format
// therefore, here we reformat to the correct datetime format based on the meta
textToCopy = d.format(constructDateTimeFormat(columnObj))
if (!dayjs(textToCopy).isValid()) {
throw new Error('Invalid Date')
}
}
await copy(textToCopy)
message.success(t('msg.info.copiedToClipboard'))
}
@ -349,7 +305,6 @@ export function useMultiSelect(
appInfo: unref(appInfo),
},
isMysql(meta.value?.base_id),
isXcdbBase(meta.value?.base_id),
)
e.preventDefault()
@ -384,7 +339,6 @@ export function useMultiSelect(
appInfo: unref(appInfo),
},
isMysql(meta.value?.base_id),
isXcdbBase(meta.value?.base_id),
)
e.preventDefault()
syncCellData?.(activeCell)

2
packages/nc-gui/lib/types.ts

@ -60,8 +60,6 @@ export interface Row {
commentCount?: number
changed?: boolean
saving?: boolean
// use in datetime picker component
isUpdatedFromCopyNPaste?: Record<string, boolean>
}
}

2
packages/nc-gui/package-lock.json generated

@ -110,7 +110,7 @@
}
},
"../nocodb-sdk": {
"version": "0.107.0-beta.1",
"version": "0.107.1",
"license": "AGPL-3.0-or-later",
"dependencies": {
"axios": "^0.21.1",

2
packages/nc-gui/plugins/a.dayjs.ts

@ -4,7 +4,6 @@ import customParseFormat from 'dayjs/plugin/customParseFormat.js'
import duration from 'dayjs/plugin/duration.js'
import utc from 'dayjs/plugin/utc.js'
import weekday from 'dayjs/plugin/weekday.js'
import timezone from 'dayjs/plugin/timezone.js'
import { defineNuxtPlugin } from '#imports'
export default defineNuxtPlugin(() => {
@ -13,5 +12,4 @@ export default defineNuxtPlugin(() => {
extend(customParseFormat)
extend(duration)
extend(weekday)
extend(timezone)
})

7
packages/nc-gui/store/project.ts

@ -82,10 +82,6 @@ export const useProject = defineStore('projectStore', () => {
return ['mysql', ClientType.MYSQL].includes(getBaseType(baseId))
}
function isSqlite(baseId?: string) {
return getBaseType(baseId) === ClientType.SQLITE
}
function isMssql(baseId?: string) {
return getBaseType(baseId) === 'mssql'
}
@ -95,7 +91,7 @@ export const useProject = defineStore('projectStore', () => {
}
function isXcdbBase(baseId?: string) {
return (bases.value.find((base) => base.id === baseId)?.is_meta as boolean) || false
return bases.value.find((base) => base.id === baseId)?.is_meta
}
const isSharedBase = computed(() => projectType === 'base')
@ -213,7 +209,6 @@ export const useProject = defineStore('projectStore', () => {
isMysql,
isMssql,
isPg,
isSqlite,
sqlUis,
isSharedBase,
loadProjectMetaInfo,

26
packages/nc-gui/utils/cell.ts

@ -1,6 +1,5 @@
import type { ColumnType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import dayjs from 'dayjs'
export const dataTypeLow = (column: ColumnType) => column.dt?.toLowerCase()
export const isBoolean = (column: ColumnType, abstractType?: any) =>
@ -54,28 +53,3 @@ export const isManualSaved = (column: ColumnType) => [UITypes.Currency].includes
export const isPrimary = (column: ColumnType) => !!column.pv
export const isPrimaryKey = (column: ColumnType) => !!column.pk
// used for LTAR and Formula
export const renderValue = (result?: any) => {
if (!result || typeof result !== 'string') {
return result
}
// cater MYSQL
result = result.replace('.000000', '')
// convert ISO string (e.g. in MSSQL) to YYYY-MM-DD hh:mm:ssZ
// e.g. 2023-05-18T05:30:00.000Z -> 2023-05-18 11:00:00+05:30
result = result.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/, (d: string) => {
return dayjs(d).format('YYYY-MM-DD HH:mm:ssZ')
})
// convert all date time values to local time
// the datetime is either YYYY-MM-DD hh:mm:ss (xcdb)
// or YYYY-MM-DD hh:mm:ss+xx:yy (ext)
return result.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(\[+-]\d{2}:\d{2})?\b/g, (d: string) => {
// TODO(timezone): retrieve the format from the corresponding column meta
// assume hh:mm at this moment
return dayjs(d).utc(!result.includes('+')).local().format('YYYY-MM-DD HH:mm')
})
}

8
packages/nc-gui/utils/dateTimeUtils.ts

@ -1,13 +1,7 @@
import dayjs from 'dayjs'
export const timeAgo = (date: any) => {
if (/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(date)) {
// if there is no timezone info, consider as UTC
// e.g. 2023-01-01 08:00:00 (MySQL)
date += '+00:00'
}
// show in local time
return dayjs(date).fromNow()
return dayjs.utc(date).fromNow()
}
export const dateFormats = [

1
packages/nc-gui/utils/index.ts

@ -23,4 +23,3 @@ export * from './browserUtils'
export * from './geoDataUtils'
export * from './mimeTypeUtils'
export * from './parseUtils'
export * from './cell'

2
packages/nc-lib-gui/package.json

@ -1,6 +1,6 @@
{
"name": "nc-lib-gui",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"description": "NocoDB GUI",
"author": {
"name": "NocoDB",

4
packages/nocodb-sdk/package-lock.json generated

@ -1,12 +1,12 @@
{
"name": "nocodb-sdk",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "nocodb-sdk",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"license": "AGPL-3.0-or-later",
"dependencies": {
"axios": "^0.21.1",

2
packages/nocodb-sdk/package.json

@ -1,6 +1,6 @@
{
"name": "nocodb-sdk",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"description": "NocoDB SDK",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",

2
packages/nocodb-sdk/src/lib/Api.ts

@ -1804,7 +1804,7 @@ export interface PluginReqType {
/** Is Plugin Active? */
active?: BoolType;
/** Plugin Input */
input?: StringOrNullType;
input?: string | null;
}
/**

20
packages/nocodb/package-lock.json generated

@ -1,12 +1,12 @@
{
"name": "nocodb",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "nocodb",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@google-cloud/storage": "^5.7.2",
@ -80,7 +80,7 @@
"mysql2": "^3.2.0",
"nanoid": "^3.1.20",
"nc-help": "^0.2.87",
"nc-lib-gui": "0.107.0-beta.1",
"nc-lib-gui": "0.107.1",
"nc-plugin": "^0.1.3",
"ncp": "^2.0.0",
"nocodb-sdk": "file:../nocodb-sdk",
@ -190,7 +190,7 @@
}
},
"../nocodb-sdk": {
"version": "0.107.0-beta.1",
"version": "0.107.1",
"license": "AGPL-3.0-or-later",
"dependencies": {
"axios": "^0.21.1",
@ -13157,9 +13157,9 @@
}
},
"node_modules/nc-lib-gui": {
"version": "0.107.0-beta.1",
"resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.107.0-beta.1.tgz",
"integrity": "sha512-xP069IpkCMrOCTKAGOWf5/GhnMVm+wqZflgt7G5CSWF3A46v5pL5SYj1yKK8HUN0v2ZVP2Agjzp44RZBv4QqqA==",
"version": "0.107.1",
"resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.107.1.tgz",
"integrity": "sha512-mAW85IXG1BkuoSACc7ZKyaozIO+OyiKSZoEUYBZQ0EtqfulRPHzBMoHw5yOUZ+wnsieMRrzCh2o+AMn9XdY0Ug==",
"dependencies": {
"express": "^4.17.1"
}
@ -28442,9 +28442,9 @@
}
},
"nc-lib-gui": {
"version": "0.107.0-beta.1",
"resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.107.0-beta.1.tgz",
"integrity": "sha512-xP069IpkCMrOCTKAGOWf5/GhnMVm+wqZflgt7G5CSWF3A46v5pL5SYj1yKK8HUN0v2ZVP2Agjzp44RZBv4QqqA==",
"version": "0.107.1",
"resolved": "https://registry.npmjs.org/nc-lib-gui/-/nc-lib-gui-0.107.1.tgz",
"integrity": "sha512-mAW85IXG1BkuoSACc7ZKyaozIO+OyiKSZoEUYBZQ0EtqfulRPHzBMoHw5yOUZ+wnsieMRrzCh2o+AMn9XdY0Ug==",
"requires": {
"express": "^4.17.1"
}

6
packages/nocodb/package.json

@ -1,6 +1,6 @@
{
"name": "nocodb",
"version": "0.107.0-beta.1",
"version": "0.107.1",
"description": "NocoDB Backend",
"main": "dist/bundle.js",
"author": {
@ -32,8 +32,6 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"watch:run": "cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/docker --log-error --project tsconfig.json\"",
"watch:run:mysql": "cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/dockerRunMysql --log-error --project tsconfig.json\"",
"watch:run:pg": "cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/dockerRunPG --log-error --project tsconfig.json\"",
"watch:run:playwright": "rm -f ./test_noco.db; cross-env DATABASE_URL=sqlite:./test_noco.db PLAYWRIGHT_TEST=true NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/testDocker --log-error --project tsconfig.json\"",
"watch:run:playwright:quick": "rm -f ./test_noco.db; cp ../../tests/playwright/fixtures/noco_0_91_7.db ./test_noco.db; cross-env DATABASE_URL=sqlite:./test_noco.db NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/docker --log-error --project tsconfig.json\"",
"watch:run:playwright:pg:cyquick": "rm -f ./test_noco.db; cp ../../tests/playwright/fixtures/noco_0_91_7.db ./test_noco.db; cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/run/dockerRunPG_CyQuick.ts --log-error --project tsconfig.json\"",
@ -113,7 +111,7 @@
"mysql2": "^3.2.0",
"nanoid": "^3.1.20",
"nc-help": "^0.2.87",
"nc-lib-gui": "0.107.0-beta.1",
"nc-lib-gui": "0.107.1",
"nc-plugin": "^0.1.3",
"ncp": "^2.0.0",
"nocodb-sdk": "file:../nocodb-sdk",

69
packages/nocodb/src/Noco.ts

@ -1,4 +1,5 @@
// import * as Sentry from '@sentry/node';
import Sentry, { Handlers } from '@sentry/node';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import clear from 'clear';
import * as express from 'express';
@ -6,20 +7,26 @@ import NcToolGui from 'nc-lib-gui';
import { IoAdapter } from '@nestjs/platform-socket.io';
import requestIp from 'request-ip';
import cookieParser from 'cookie-parser';
import { T } from 'nc-help';
import { v4 as uuidv4 } from 'uuid';
import dotenv from 'dotenv';
import { AppModule } from './app.module';
import { NC_LICENSE_KEY } from './constants';
import Store from './models/Store';
import { MetaTable } from './utils/globals';
import type { IEventEmitter } from './modules/event-emitter/event-emitter.interface';
import type { Express } from 'express';
import type * as http from 'http';
dotenv.config();
export default class Noco {
private static _this: Noco;
private static ee: boolean;
public static readonly env: string = '_noco';
private static _httpServer: http.Server;
private static _server: Express;
private static logger = new Logger(Noco.name);
public static get dashboardUrl(): string {
let siteUrl = `http://localhost:${process.env.PORT || 8080}`;
@ -42,7 +49,6 @@ export default class Noco {
public readonly metaMgrv2: any;
public env: string;
private ncToolApi;
private config: any;
private requestContext: any;
@ -102,6 +108,8 @@ export default class Noco {
const nestApp = await NestFactory.create(AppModule);
this.initSentry(nestApp);
nestApp.useWebSocketAdapter(new IoAdapter(httpServer));
nestApp.use(requestIp.mw());
@ -115,6 +123,9 @@ export default class Noco {
const dashboardPath = process.env.NC_DASHBOARD_URL || '/dashboard';
server.use(NcToolGui.expressMiddleware(dashboardPath));
server.get('/', (_req, res) => res.redirect(dashboardPath));
this.initSentryErrorHandler(server);
return nestApp.getHttpAdapter().getInstance();
}
@ -125,4 +136,56 @@ export default class Noco {
public static get server(): Express {
return Noco._server;
}
public static async initJwt(): Promise<any> {
if (this.config?.auth?.jwt) {
if (!this.config.auth.jwt.secret) {
let secret = (
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
})
)?.value;
if (!secret) {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
value: (secret = uuidv4()),
});
}
this.config.auth.jwt.secret = secret;
}
this.config.auth.jwt.options = this.config.auth.jwt.options || {};
if (!this.config.auth.jwt.options?.expiresIn) {
this.config.auth.jwt.options.expiresIn =
process.env.NC_JWT_EXPIRES_IN ?? '10h';
}
}
let serverId = (
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_server_id',
})
)?.value;
if (!serverId) {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_server_id',
value: (serverId = T.id),
});
}
process.env.NC_SERVER_UUID = serverId;
}
private static initSentryErrorHandler(router) {
if (process.env.NC_SENTRY_DSN) {
router.use(Handlers.errorHandler());
}
}
private static initSentry(router) {
if (process.env.NC_SENTRY_DSN) {
Sentry.init({ dsn: process.env.NC_SENTRY_DSN });
// The request handler must be the first middleware on the app
router.use(Handlers.requestHandler());
}
}
}

51
packages/nocodb/src/app.module.ts

@ -1,35 +1,25 @@
import { Inject, Module, RequestMethod } from '@nestjs/common';
import { Module, RequestMethod } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { BullModule } from '@nestjs/bull';
import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter';
import { Connection } from './connection/connection';
import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter';
import NcPluginMgrv2 from './helpers/NcPluginMgrv2';
import { GlobalMiddleware } from './middlewares/global/global.middleware';
import { GuiMiddleware } from './middlewares/gui/gui.middleware';
import { PublicMiddleware } from './middlewares/public/public.middleware';
import { DatasModule } from './modules/datas/datas.module';
import { IEventEmitter } from './modules/event-emitter/event-emitter.interface';
import { EventEmitterModule } from './modules/event-emitter/event-emitter.module';
import { AuthService } from './services/auth.service';
import { UsersModule } from './modules/users/users.module';
import { MetaService } from './meta/meta.service';
import Noco from './Noco';
import { TestModule } from './modules/test/test.module';
import { GlobalModule } from './modules/global/global.module';
import { HookHandlerService } from './services/hook-handler.service';
import { LocalStrategy } from './strategies/local.strategy';
import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy';
import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy';
import NcConfigFactory from './utils/NcConfigFactory';
import NcUpgrader from './version-upgrader/NcUpgrader';
import { MetasModule } from './modules/metas/metas.module';
import NocoCache from './cache/NocoCache';
import { JobsModule } from './modules/jobs/jobs.module';
import type {
MiddlewareConsumer,
OnApplicationBootstrap,
} from '@nestjs/common';
import { AppInitService } from './services/app-init.service';
import type { MiddlewareConsumer } from '@nestjs/common';
@Module({
imports: [
@ -60,15 +50,10 @@ import type {
AuthTokenStrategy,
BaseViewStrategy,
HookHandlerService,
AppInitService,
],
})
export class AppModule implements OnApplicationBootstrap {
constructor(
private readonly connection: Connection,
private readonly metaService: MetaService,
@Inject('IEventEmitter') private readonly eventEmitter: IEventEmitter,
) {}
export class AppModule {
// Global Middleware
configure(consumer: MiddlewareConsumer) {
consumer
@ -79,30 +64,4 @@ export class AppModule implements OnApplicationBootstrap {
.apply(GlobalMiddleware)
.forRoutes({ path: '*', method: RequestMethod.ALL });
}
// app init
async onApplicationBootstrap(): Promise<void> {
process.env.NC_VERSION = '0105004';
await NocoCache.init();
await this.connection.init();
await NcConfigFactory.metaDbCreateIfNotExist(this.connection.config);
await this.metaService.init();
// todo: remove
// temporary hack
Noco._ncMeta = this.metaService;
Noco.config = this.connection.config;
Noco.eventEmitter = this.eventEmitter;
// init plugin manager
await NcPluginMgrv2.init(Noco.ncMeta);
await Noco.loadEEState();
// run upgrader
await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta });
}
}

214
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -1,8 +1,6 @@
import autoBind from 'auto-bind';
import groupBy from 'lodash/groupBy';
import DataLoader from 'dataloader';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
import { nocoExecute } from 'nc-help';
import {
AuditOperationSubTypes,
@ -18,16 +16,8 @@ import DOMPurify from 'isomorphic-dompurify';
import { v4 as uuidv4 } from 'uuid';
import { NcError } from '../helpers/catchError';
import getAst from '../helpers/getAst';
import {
Audit,
Base,
Column,
Filter,
Model,
Project,
Sort,
View,
} from '../models';
import { Audit, Column, Filter, Model, Project, Sort, View } from '../models';
import { sanitize, unsanitize } from '../helpers/sqlSanitize';
import {
COMPARISON_OPS,
@ -56,9 +46,7 @@ import type {
SelectOption,
} from '../models';
import type { Knex } from 'knex';
import type { BoolType, SortType } from 'nocodb-sdk';
dayjs.extend(utc);
import type { SortType } from 'nocodb-sdk';
const GROUP_COL = '__nc_group_id';
@ -1612,61 +1600,6 @@ class BaseModelSqlv2 {
if (!checkColumnRequired(column, fields, extractPkAndPv)) continue;
switch (column.uidt) {
case UITypes.DateTime:
if (this.isMySQL) {
// MySQL stores timestamp in UTC but display in timezone
// To verify the timezone, run `SELECT @@global.time_zone, @@session.time_zone;`
// If it's SYSTEM, then the timezone is read from the configuration file
// if a timezone is set in a DB, the retrieved value would be converted to the corresponding timezone
// for example, let's say the global timezone is +08:00 in DB
// the value 2023-01-01 10:00:00 (UTC) would display as 2023-01-01 18:00:00 (UTC+8)
// our existing logic is based on UTC, during the query, we need to take the UTC value
// hence, we use CONVERT_TZ to convert back to UTC value
res[sanitize(column.title || column.column_name)] =
this.dbDriver.raw(
`CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`,
[
`${sanitize(alias || this.model.table_name)}.${
column.column_name
}`,
],
);
break;
} else if (this.isPg) {
// if there is no timezone info, convert it to UTC
if (
column.dt !== 'timestamp with time zone' &&
column.dt !== 'timestamptz'
) {
res[sanitize(column.title || column.column_name)] = this.dbDriver
.raw(
`?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`,
[
`${sanitize(alias || this.model.table_name)}.${
column.column_name
}`,
],
)
.wrap('(', ')');
break;
}
} else if (this.isMssql) {
// if there is no timezone info, convert to database timezone, then convert to UTC
if (column.dt !== 'datetime2') {
const col = `${sanitize(alias || this.model.table_name)}.${
column.column_name
}`;
res[sanitize(column.title || column.column_name)] =
this.dbDriver.raw(
`SWITCHOFFSET(??, DATEPART(TZOFFSET, ??)) AT TIME ZONE 'UTC'`,
[col, col],
);
}
}
res[sanitize(column.title || column.column_name)] = sanitize(
`${alias || this.model.table_name}.${column.column_name}`,
);
break;
case 'LinkToAnotherRecord':
case 'Lookup':
break;
@ -1794,11 +1727,7 @@ class BaseModelSqlv2 {
await populatePk(this.model, data);
// todo: filter based on view
const insertObj = await this.model.mapAliasToColumn(
data,
this.clientMeta,
this.dbDriver,
);
const insertObj = await this.model.mapAliasToColumn(data);
await this.validate(insertObj);
@ -1936,11 +1865,7 @@ class BaseModelSqlv2 {
async updateByPk(id, data, trx?, cookie?) {
try {
const updateObj = await this.model.mapAliasToColumn(
data,
this.clientMeta,
this.dbDriver,
);
const updateObj = await this.model.mapAliasToColumn(data);
await this.validate(data);
@ -1988,16 +1913,6 @@ class BaseModelSqlv2 {
return this.getTnPath(this.model);
}
public get clientMeta() {
return {
isSqlite: this.isSqlite,
isMssql: this.isMssql,
isPg: this.isPg,
isMySQL: this.isMySQL,
// isSnowflake: this.isSnowflake,
};
}
get isSqlite() {
return this.clientType === 'sqlite3';
}
@ -2026,11 +1941,7 @@ class BaseModelSqlv2 {
// const driver = trx ? trx : await this.dbDriver.transaction();
try {
await populatePk(this.model, data);
const insertObj = await this.model.mapAliasToColumn(
data,
this.clientMeta,
this.dbDriver,
);
const insertObj = await this.model.mapAliasToColumn(data);
let rowId = null;
const postInsertOps = [];
@ -2187,11 +2098,7 @@ class BaseModelSqlv2 {
: await Promise.all(
datas.map(async (d) => {
await populatePk(this.model, d);
return this.model.mapAliasToColumn(
d,
this.clientMeta,
this.dbDriver,
);
return this.model.mapAliasToColumn(d);
}),
);
@ -2254,11 +2161,7 @@ class BaseModelSqlv2 {
const updateDatas = raw
? datas
: await Promise.all(
datas.map((d) =>
this.model.mapAliasToColumn(d, this.clientMeta, this.dbDriver),
),
);
: await Promise.all(datas.map((d) => this.model.mapAliasToColumn(d)));
const prevData = [];
const newData = [];
@ -2310,11 +2213,7 @@ class BaseModelSqlv2 {
) {
try {
let count = 0;
const updateData = await this.model.mapAliasToColumn(
data,
this.clientMeta,
this.dbDriver,
);
const updateData = await this.model.mapAliasToColumn(data);
await this.validate(updateData);
const pkValues = await this._extractPksValues(updateData);
if (pkValues) {
@ -2360,9 +2259,7 @@ class BaseModelSqlv2 {
let transaction;
try {
const deleteIds = await Promise.all(
ids.map((d) =>
this.model.mapAliasToColumn(d, this.clientMeta, this.dbDriver),
),
ids.map((d) => this.model.mapAliasToColumn(d)),
);
const deleted = [];
@ -3248,23 +3145,16 @@ class BaseModelSqlv2 {
} else {
query = sanitize(query);
}
let data =
return this.convertAttachmentType(
this.isPg || this.isSnowflake
? (await this.dbDriver.raw(query))?.rows
: query.slice(0, 6) === 'select' && !this.isMssql
? await this.dbDriver.from(
this.dbDriver.raw(query).wrap('(', ') __nc_alias'),
)
: await this.dbDriver.raw(query);
// update attachment fields
data = this.convertAttachmentType(data, childTable);
// update date time fields
data = this.convertDateFormat(data, childTable);
return data;
: await this.dbDriver.raw(query),
childTable,
);
}
private _convertAttachmentType(
@ -3302,82 +3192,6 @@ class BaseModelSqlv2 {
}
return data;
}
private _convertDateFormat(
dateTimeColumns: Record<string, any>[],
d: Record<string, any>,
) {
if (!d) return d;
for (const col of dateTimeColumns) {
if (!d[col.title]) continue;
let keepLocalTime = true;
if (this.isSqlite) {
if (!col.cdf) {
if (
d[col.title].indexOf('-') === -1 &&
d[col.title].indexOf('+') === -1 &&
d[col.title].slice(-1) !== 'Z'
) {
// if there is no timezone info,
// we assume the input is on NocoDB server timezone
// then we convert to UTC from server timezone
// e.g. 2023-04-27 10:00:00 (IST) -> 2023-04-27 04:30:00+00:00
d[col.title] = dayjs(d[col.title])
.tz(Intl.DateTimeFormat().resolvedOptions().timeZone)
.utc()
.format('YYYY-MM-DD HH:mm:ssZ');
continue;
} else {
// otherwise, we convert from the given timezone to UTC
keepLocalTime = false;
}
}
}
if (
this.isPg &&
(col.dt === 'timestamp with time zone' || col.dt === 'timestamptz')
) {
// postgres - timezone already attached to input
// e.g. 2023-05-11 16:16:51+08:00
keepLocalTime = false;
}
if (d[col.title] instanceof Date) {
// e.g. MSSQL
// Wed May 10 2023 17:47:46 GMT+0800 (Hong Kong Standard Time)
keepLocalTime = false;
}
// e.g. 01.01.2022 10:00:00+05:30 -> 2022-01-01 04:30:00+00:00
// e.g. 2023-05-09 11:41:49 -> 2023-05-09 11:41:49+00:00
d[col.title] = dayjs(d[col.title])
// keep the local time
.utc(keepLocalTime)
// show the timezone even for Mysql
.format('YYYY-MM-DD HH:mm:ssZ');
}
return d;
}
private convertDateFormat(data: Record<string, any>, childTable?: Model) {
// Show the date time in UTC format in API response
// e.g. 2022-01-01 04:30:00+00:00
if (data) {
const dateTimeColumns = (
childTable ? childTable.columns : this.model.columns
).filter((c) => c.uidt === UITypes.DateTime);
if (dateTimeColumns.length) {
if (Array.isArray(data)) {
data = data.map((d) => this._convertDateFormat(dateTimeColumns, d));
} else {
this._convertDateFormat(dateTimeColumns, data);
}
}
}
return data;
}
}
function extractSortsObject(

14
packages/nocodb/src/db/CustomKnex.ts

@ -1,24 +1,12 @@
import { Knex, knex } from 'knex';
import { SnowflakeClient } from 'nc-help';
import pg, { types } from 'pg';
import dayjs from 'dayjs';
import { types } from 'pg';
import Filter from '../models/Filter';
import type { FilterType } from 'nocodb-sdk';
import type { BaseModelSql } from './BaseModelSql';
// For the code, check out
// https://raw.githubusercontent.com/brianc/node-pg-types/master/lib/builtins.js
// override parsing date column to Date()
types.setTypeParser(1082, (val) => val);
// override timestamp
types.setTypeParser(1114, (val) => {
return dayjs(val).format('YYYY-MM-DD HH:mm:ss');
});
// override timestampz
types.setTypeParser(1184, (val) => {
return dayjs(val).format('YYYY-MM-DD HH:mm:ssZ');
});
const opMappingGen = {
eq: '=',

30
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -537,36 +537,6 @@ async function _formulaQueryBuilder(
};
};
break;
case UITypes.DateTime:
if (knex.clientType().startsWith('mysql')) {
aliasToColumn[col.id] = async (): Promise<any> => {
return {
builder: knex.raw(
`CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`,
[col.column_name],
),
};
};
} else if (
knex.clientType() === 'pg' &&
col.dt !== 'timestamp with time zone' &&
col.dt !== 'timestamptz'
) {
aliasToColumn[col.id] = async (): Promise<any> => {
return {
builder: knex
.raw(
`?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`,
[col.column_name],
)
.wrap('(', ')'),
};
};
} else {
aliasToColumn[col.id] = () =>
Promise.resolve({ builder: col.column_name });
}
break;
default:
aliasToColumn[col.id] = () =>
Promise.resolve({ builder: col.column_name });

34
packages/nocodb/src/meta/meta.service.ts

@ -6,9 +6,7 @@ import {
OnModuleInit,
Optional,
} from '@nestjs/common';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import { customAlphabet } from 'nanoid';
import CryptoJS from 'crypto-js';
import { Connection } from '../connection/connection';
@ -18,9 +16,6 @@ import XcMigrationSourcev2 from './migrations/XcMigrationSourcev2';
import XcMigrationSource from './migrations/XcMigrationSource';
import type { Knex } from 'knex';
dayjs.extend(utc);
dayjs.extend(timezone);
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
// todo: tobe fixed
@ -261,8 +256,8 @@ export class MetaService {
await this.knexConnection(target).insert({
...insertObj,
created_at: this.now(),
updated_at: this.now(),
created_at: data?.created_at || this.knexConnection?.fn?.now(),
updated_at: data?.updated_at || this.knexConnection?.fn?.now(),
});
return insertObj;
}
@ -544,9 +539,9 @@ export class MetaService {
return this.knexConnection(target).insert({
db_alias: dbAlias,
project_id,
created_at: this.knexConnection?.fn?.now(),
updated_at: this.knexConnection?.fn?.now(),
...data,
created_at: this.now(),
updated_at: this.now(),
});
}
@ -694,7 +689,7 @@ export class MetaService {
delete data.created_at;
query.update({ ...data, updated_at: this.now() });
query.update({ ...data, updated_at: this.knexConnection?.fn?.now() });
if (typeof idOrCondition !== 'object') {
query.where('id', idOrCondition);
} else if (idOrCondition) {
@ -815,8 +810,8 @@ export class MetaService {
// todo: check project name used or not
await this.knexConnection('nc_projects').insert({
...project,
created_at: this.now(),
updated_at: this.now(),
created_at: this.knexConnection?.fn?.now(),
updated_at: this.knexConnection?.fn?.now(),
});
// todo
@ -1035,19 +1030,6 @@ export class MetaService {
return nanoid();
}
private isMySQL(): boolean {
return (
this.connection.clientType() === 'mysql' ||
this.connection.clientType() === 'mysql2'
);
}
private now(): any {
return dayjs()
.utc()
.format(this.isMySQL() ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ');
}
public async audit(
project_id: string,
dbAlias: string,

63
packages/nocodb/src/models/Model.ts

@ -1,5 +1,4 @@
import { isVirtualCol, ModelTypes, UITypes, ViewTypes } from 'nocodb-sdk';
import dayjs from 'dayjs';
import { BaseModelSqlv2 } from '../db/BaseModelSqlv2';
import Noco from '../Noco';
import { parseMetaProp } from '../utils/modelUtils';
@ -16,7 +15,6 @@ import { sanitize } from '../helpers/sqlSanitize';
import { extractProps } from '../helpers/extractProps';
import Audit from './Audit';
import View from './View';
import Base from './Base';
import Column from './Column';
import type { BoolType, TableReqType, TableType } from 'nocodb-sdk';
import type { XKnex } from '../db/CustomKnex';
@ -445,18 +443,8 @@ export default class Model implements TableType {
return true;
}
async mapAliasToColumn(
data,
clientMeta = {
isMySQL: false,
isSqlite: false,
isMssql: false,
isPg: false,
},
knex,
) {
async mapAliasToColumn(data) {
const insertObj = {};
const base = await Base.get(this.base_id);
for (const col of await this.getColumns()) {
if (isVirtualCol(col)) continue;
let val =
@ -467,55 +455,6 @@ export default class Model implements TableType {
if (col.uidt === UITypes.Attachment && typeof val !== 'string') {
val = JSON.stringify(val);
}
if (col.uidt === UITypes.DateTime && dayjs(val).isValid()) {
const { isMySQL, isSqlite, isMssql, isPg } = clientMeta;
if (
val.indexOf('-') < 0 &&
val.indexOf('+') < 0 &&
val.slice(-1) !== 'Z'
) {
// if no timezone is given,
// then append +00:00 to make it as UTC
val += '+00:00';
}
if (isMySQL) {
// first convert the value to utc
// from UI
// e.g. 2022-01-01 20:00:00Z -> 2022-01-01 20:00:00
// from API
// e.g. 2022-01-01 20:00:00+08:00 -> 2022-01-01 12:00:00
// if timezone info is not found - considered as utc
// e.g. 2022-01-01 20:00:00 -> 2022-01-01 20:00:00
// if timezone info is found
// e.g. 2022-01-01 20:00:00Z -> 2022-01-01 20:00:00
// e.g. 2022-01-01 20:00:00+00:00 -> 2022-01-01 20:00:00
// e.g. 2022-01-01 20:00:00+08:00 -> 2022-01-01 12:00:00
// then we use CONVERT_TZ to convert that in the db timezone
val = knex.raw(`CONVERT_TZ(?, '+00:00', @@GLOBAL.time_zone)`, [
dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'),
]);
} else if (isSqlite) {
// e.g. 2022-01-01T10:00:00.000Z -> 2022-01-01 04:30:00+00:00
val = dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ');
} else if (isPg) {
// convert to UTC
// e.g. 2023-01-01T12:00:00.000Z -> 2023-01-01 12:00:00+00:00
// then convert to db timezone
val = knex.raw(`? AT TIME ZONE CURRENT_SETTING('timezone')`, [
dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ'),
]);
} else if (isMssql) {
// e.g. 2023-05-10T08:49:32.000Z -> 2023-05-10 08:49:32-08:00
// then convert to db timezone
val = knex.raw(
`SWITCHOFFSET(? AT TIME ZONE 'UTC', SYSDATETIMEOFFSET()`,
[dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ')],
);
} else {
// e.g. 2023-01-01T12:00:00.000Z -> 2023-01-01 12:00:00+00:00
val = dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ');
}
}
insertObj[sanitize(col.column_name)] = val;
}
}

20
packages/nocodb/src/modules/global/global.module.ts

@ -1,19 +1,27 @@
import { Global, Module } from '@nestjs/common';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { ExtractJwt } from 'passport-jwt';
import {
AppInitService,
appInitServiceProvider,
} from '../../services/app-init.service';
import { SocketGateway } from '../../gateways/socket.gateway';
import { Connection } from '../../connection/connection';
import { GlobalGuard } from '../../guards/global/global.guard';
import { MetaService } from '../../meta/meta.service';
import Noco from '../../Noco';
import { JwtStrategy } from '../../strategies/jwt.strategy';
import NcConfigFactory from '../../utils/NcConfigFactory';
import { UsersService } from '../../services/users/users.service';
import type { Provider } from '@nestjs/common';
export const JwtStrategyProvider: Provider = {
provide: JwtStrategy,
useFactory: async (usersService: UsersService) => {
const config = await NcConfigFactory.make();
useFactory: async (
usersService: UsersService,
appInitService: AppInitService,
) => {
const config = appInitService.appConfig;
await Noco.initJwt();
const options = {
// ignoreExpiration: false,
@ -26,13 +34,14 @@ export const JwtStrategyProvider: Provider = {
return new JwtStrategy(options, usersService);
},
inject: [UsersService],
inject: [UsersService, AppInitService],
};
@Global()
@Module({
imports: [],
providers: [
appInitServiceProvider,
Connection,
MetaService,
UsersService,
@ -41,6 +50,7 @@ export const JwtStrategyProvider: Provider = {
SocketGateway,
],
exports: [
AppInitService,
Connection,
MetaService,
JwtStrategyProvider,

19
packages/nocodb/src/services/app-init.service.spec.ts

@ -0,0 +1,19 @@
import { Test } from '@nestjs/testing';
import { AppInitService } from './app-init.service';
import type { TestingModule } from '@nestjs/testing';
describe('AppInitService', () => {
let service: AppInitService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AppInitService],
}).compile();
service = module.get<AppInitService>(AppInitService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

68
packages/nocodb/src/services/app-init.service.ts

@ -0,0 +1,68 @@
import { Inject, Injectable } from '@nestjs/common';
import NocoCache from '../cache/NocoCache';
import { Connection } from '../connection/connection';
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2';
import { MetaService } from '../meta/meta.service';
import Noco from '../Noco';
import NcConfigFactory from '../utils/NcConfigFactory';
import NcUpgrader from '../version-upgrader/NcUpgrader';
import type { IEventEmitter } from '../modules/event-emitter/event-emitter.interface';
import type { Provider } from '@nestjs/common';
export class AppInitService {
private readonly config: any;
constructor(config) {
this.config = config;
}
get appConfig(): any {
return this.config;
}
}
export const appInitServiceProvider: Provider = {
provide: AppInitService,
// initialize app,
// 1. init cache
// 2. init db connection and create if not exist
// 3. init meta and set to Noco
// 4. init jwt
// 5. init plugin manager
// 6. run upgrader
useFactory: async (
connection: Connection,
metaService: MetaService,
eventEmitter: IEventEmitter,
) => {
process.env.NC_VERSION = '0105004';
await NocoCache.init();
await connection.init();
await NcConfigFactory.metaDbCreateIfNotExist(connection.config);
await metaService.init();
// todo: remove
// temporary hack
Noco._ncMeta = metaService;
Noco.config = connection.config;
Noco.eventEmitter = eventEmitter;
// init jwt secret
await Noco.initJwt();
// init plugin manager
await NcPluginMgrv2.init(Noco.ncMeta);
await Noco.loadEEState();
// run upgrader
await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta });
// todo: move app config to app-init service
return new AppInitService(connection.config);
},
inject: [Connection, MetaService, 'IEventEmitter'],
};

10
packages/nocodb/src/utils/NcConfigFactory.ts

@ -100,7 +100,7 @@ export default class NcConfigFactory {
ncConfig.auth = {
jwt: {
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key',
secret: process.env.NC_AUTH_JWT_SECRET,
},
};
@ -421,7 +421,7 @@ export default class NcConfigFactory {
if (process.env.NC_AUTH_ADMIN_SECRET) {
config.auth = {
masterKey: {
secret: process.env.NC_AUTH_ADMIN_SECRET ?? 'temporary-key',
secret: process.env.NC_AUTH_ADMIN_SECRET,
},
};
} else if (process.env.NC_NO_AUTH) {
@ -436,7 +436,7 @@ export default class NcConfigFactory {
dbAlias:
process.env.NC_AUTH_JWT_DB_ALIAS ||
config.envs['_noco'].db[0].meta.dbAlias,
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key',
secret: process.env.NC_AUTH_JWT_SECRET,
},
};
}
@ -536,7 +536,7 @@ export default class NcConfigFactory {
if (process.env.NC_AUTH_ADMIN_SECRET) {
config.auth = {
masterKey: {
secret: process.env.NC_AUTH_ADMIN_SECRET ?? 'temporary-key',
secret: process.env.NC_AUTH_ADMIN_SECRET,
},
};
} else if (process.env.NC_NO_AUTH) {
@ -551,7 +551,7 @@ export default class NcConfigFactory {
dbAlias:
process.env.NC_AUTH_JWT_DB_ALIAS ||
config.envs['_noco'].db[0].meta.dbAlias,
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key',
secret: process.env.NC_AUTH_JWT_SECRET,
},
};
}

51
packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts

@ -1,20 +1,20 @@
import 'mocha';
import { expect } from 'chai';
import { BaseModelSqlv2 } from '../../../../src/db/BaseModelSqlv2';
import NcConnectionMgrv2 from '../../../../src/utils/common/NcConnectionMgrv2';
import { BaseModelSqlv2 } from '../../../../src/db/BaseModelSqlv2'
import NcConnectionMgrv2 from '../../../../src/utils/common/NcConnectionMgrv2'
import init from '../../init';
import { createProject } from '../../factory/project';
import { createTable } from '../../factory/table';
import Base from '../../../../src/models/Base';
import Model from '../../../../src/models/Model';
import Project from '../../../../src/models/Project';
import View from '../../../../src/models/View';
import { createRow, generateDefaultRowAttributes } from '../../factory/row';
import Audit from '../../../../src/models/Audit';
import { expect } from 'chai';
import Filter from '../../../../src/models/Filter';
import { createLtarColumn } from '../../factory/column';
import LinkToAnotherRecordColumn from '../../../../src/models/LinkToAnotherRecordColumn';
import { isPg, isSqlite } from '../../init/db';
import type View from '../../../../src/models/View';
import type Project from '../../../../src/models/Project';
import type Model from '../../../../src/models/Model';
import type LinkToAnotherRecordColumn from '../../../../src/models/LinkToAnotherRecordColumn';
function baseModelSqlTests() {
let context;
@ -44,11 +44,11 @@ function baseModelSqlTests() {
};
const columns = await table.getColumns();
const inputData: any = generateDefaultRowAttributes({ columns });
let inputData: any = generateDefaultRowAttributes({ columns });
const response = await baseModelSql.insert(
generateDefaultRowAttributes({ columns }),
undefined,
request,
request
);
const insertedRow = (await baseModelSql.list())[0];
@ -61,10 +61,6 @@ function baseModelSqlTests() {
response.CreatedAt = new Date(response.CreatedAt).toISOString();
response.UpdatedAt = new Date(response.UpdatedAt).toISOString();
} else if (isSqlite(context)) {
// append +00:00 to the date string
inputData.CreatedAt = `${inputData.CreatedAt}+00:00`;
inputData.UpdatedAt = `${inputData.UpdatedAt}+00:00`;
}
expect(insertedRow).to.include(inputData);
@ -110,10 +106,6 @@ function baseModelSqlTests() {
if (isPg(context)) {
inputData.CreatedAt = new Date(inputData.CreatedAt).toISOString();
inputData.UpdatedAt = new Date(inputData.UpdatedAt).toISOString();
} else if (isSqlite(context)) {
// append +00:00 to the date string
inputData.CreatedAt = `${inputData.CreatedAt}+00:00`;
inputData.UpdatedAt = `${inputData.UpdatedAt}+00:00`;
}
expect(insertedRows[index]).to.include(inputData);
});
@ -153,7 +145,7 @@ function baseModelSqlTests() {
expect(updatedRow).to.include({ Id: rowId, Title: 'test' });
const rowUpdatedAudit = (await Audit.projectAuditList(project.id, {})).find(
(audit) => audit.op_sub_type === 'UPDATE',
(audit) => audit.op_sub_type === 'UPDATE'
);
expect(rowUpdatedAudit).to.include({
user: 'test@example.com',
@ -164,8 +156,7 @@ function baseModelSqlTests() {
row_id: '1',
op_type: 'DATA',
op_sub_type: 'UPDATE',
description:
'Record with ID 1 has been updated in Table Table1_Title.\nColumn "Title" got changed from "test-0" to "test"',
description: 'Record with ID 1 has been updated in Table Table1_Title.\nColumn "Title" got changed from "test-0" to "test"',
});
});
@ -187,7 +178,7 @@ function baseModelSqlTests() {
await baseModelSql.bulkUpdate(
insertedRows.map((row) => ({ ...row, Title: `new-${row['Title']}` })),
{ cookie: request },
{ cookie: request }
);
const updatedRows = await baseModelSql.list();
@ -238,7 +229,7 @@ function baseModelSqlTests() {
],
},
{ Title: 'new-1' },
{ cookie: request },
{ cookie: request }
);
const updatedRows = await baseModelSql.list();
@ -286,7 +277,7 @@ function baseModelSqlTests() {
console.log('Delete record', await Audit.projectAuditList(project.id, {}));
const rowDeletedAudit = (await Audit.projectAuditList(project.id, {})).find(
(audit) => audit.op_sub_type === 'DELETE',
(audit) => audit.op_sub_type === 'DELETE'
);
expect(rowDeletedAudit).to.include({
user: 'test@example.com',
@ -318,7 +309,7 @@ function baseModelSqlTests() {
insertedRows
.filter((row) => row['Id'] < 5)
.map((row) => ({ id: row['Id'] })),
{ cookie: request },
{ cookie: request }
);
const remainingRows = await baseModelSql.list();
@ -368,7 +359,7 @@ function baseModelSqlTests() {
}),
],
},
{ cookie: request },
{ cookie: request }
);
const remainingRows = await baseModelSql.list();
@ -423,7 +414,7 @@ function baseModelSqlTests() {
[ltarColumn.title]: [{ Id: childRow['Id'] }],
},
undefined,
request,
request
);
const childBaseModel = new BaseModelSqlv2({
@ -479,7 +470,7 @@ function baseModelSqlTests() {
await baseModelSql.insert(
generateDefaultRowAttributes({ columns }),
undefined,
request,
request
);
const insertedRow = await baseModelSql.readByPk(1);
@ -496,7 +487,7 @@ function baseModelSqlTests() {
view,
});
const updatedChildRow = await childBaseModel.readByPk(
insertedChildRow['Id'],
insertedChildRow['Id']
);
expect(updatedChildRow[childCol.column_name]).to.equal(insertedRow['Id']);
@ -547,7 +538,7 @@ function baseModelSqlTests() {
await baseModelSql.insert(
generateDefaultRowAttributes({ columns }),
undefined,
request,
request
);
const insertedRow = await baseModelSql.readByPk(1);
@ -571,7 +562,7 @@ function baseModelSqlTests() {
view,
});
const updatedChildRow = await childBaseModel.readByPk(
insertedChildRow['Id'],
insertedChildRow['Id']
);
expect(updatedChildRow[childCol.column_name]).to.be.null;

205
packages/nocodb/tests/unit/rest/tests/tableRow.test.ts

@ -1,9 +1,8 @@
import 'mocha';
import request from 'supertest';
import { UITypes } from 'nocodb-sdk';
import { expect } from 'chai';
import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/project';
import request from 'supertest';
import { ColumnType, UITypes } from 'nocodb-sdk';
import {
createColumn,
createLookupColumn,
@ -12,18 +11,18 @@ import {
} from '../../factory/column';
import { createTable, getTable } from '../../factory/table';
import {
createBulkRows,
createChildRow,
createRow,
generateDefaultRowAttributes,
getOneRow,
getRow,
listRow,
createBulkRows,
} from '../../factory/row';
import { isMysql, isPg, isSqlite } from '../../init/db';
import type { ColumnType } from 'nocodb-sdk';
import type Model from '../../../../src/models/Model';
import type Project from '../../../../src/models/Project';
import Model from '../../../../src/models/Model';
import Project from '../../../../src/models/Project';
import { expect } from 'chai';
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(row).sort().join(',');
@ -161,7 +160,7 @@ function tableTest() {
it('Get desc sorted table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const visibleColumns = [firstNameColumn];
const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'desc' }];
@ -215,7 +214,7 @@ function tableTest() {
it('Get asc sorted table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const visibleColumns = [firstNameColumn];
const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'asc' }];
@ -428,7 +427,7 @@ function tableTest() {
});
const paymentListColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'Payment List',
(c) => c.title === 'Payment List'
);
const nestedFilter = {
@ -514,11 +513,11 @@ function tableTest() {
});
const paymentListColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'Payment List',
(c) => c.title === 'Payment List'
);
const returnDateColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'ReturnDate',
(c) => c.title === 'ReturnDate'
);
const nestedFilter = {
@ -631,15 +630,15 @@ function tableTest() {
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List',
(c) => c.title === 'Payment List'
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active',
(c) => c.title === 'Active'
);
const addressColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Address',
(c) => c.title === 'Address'
);
const nestedFilter = [
@ -787,11 +786,11 @@ function tableTest() {
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List',
(c) => c.title === 'Payment List'
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active',
(c) => c.title === 'Active'
);
const nestedFields = {
@ -867,7 +866,7 @@ function tableTest() {
}
const nestedRentalResponse = Object.keys(
ascResponse.body.list[0]['Rental List'],
ascResponse.body.list[0]['Rental List']
);
if (
nestedRentalResponse.includes('ReturnDate') &&
@ -878,9 +877,7 @@ function tableTest() {
}
});
// rollup usage in formula is currently not supported
// work in progress
it.skip('Sorted Formula column on rollup customer table', async function () {
it('Sorted Formula column on rollup customer table', async function () {
const rollupColumnTitle = 'Number of rentals';
const rollupColumn = await createRollupColumn(context, {
project: sakilaProject,
@ -917,7 +914,7 @@ function tableTest() {
if (
(response.body.list as Array<any>).every(
(row) =>
parseInt(row['Formula']) !== parseInt(row[rollupColumnTitle]) + 10,
parseInt(row['Formula']) !== parseInt(row[rollupColumnTitle]) + 10
)
) {
throw new Error('Wrong formula');
@ -1001,13 +998,13 @@ function tableTest() {
it('Find one sorted table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const visibleColumns = [firstNameColumn];
let response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`
)
.set('xc-auth', context.token)
.query({
@ -1028,7 +1025,7 @@ function tableTest() {
response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`
)
.set('xc-auth', context.token)
.query({
@ -1050,7 +1047,7 @@ function tableTest() {
it('Find one desc sorted and with rollup table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const rollupColumn = await createRollupColumn(context, {
@ -1067,7 +1064,7 @@ function tableTest() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`
)
.set('xc-auth', context.token)
.query({
@ -1098,11 +1095,11 @@ function tableTest() {
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List',
(c) => c.title === 'Payment List'
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active',
(c) => c.title === 'Active'
);
const nestedFields = {
@ -1155,7 +1152,7 @@ function tableTest() {
const ascResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`
)
.set('xc-auth', context.token)
.query({
@ -1182,7 +1179,7 @@ function tableTest() {
it('Groupby desc sorted and with rollup table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const rollupColumn = await createRollupColumn(context, {
@ -1199,7 +1196,7 @@ function tableTest() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/groupby`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/groupby`
)
.set('xc-auth', context.token)
.query({
@ -1218,7 +1215,7 @@ function tableTest() {
it('Groupby desc sorted and with rollup table data list with required columns', async function () {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName',
(col) => col.title === 'FirstName'
);
const rollupColumn = await createRollupColumn(context, {
@ -1235,7 +1232,7 @@ function tableTest() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/groupby`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/groupby`
)
.set('xc-auth', context.token)
.query({
@ -1263,7 +1260,7 @@ function tableTest() {
const readResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${row['CustomerId']}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${row['CustomerId']}`
)
.set('xc-auth', context.token)
.expect(200);
@ -1399,7 +1396,7 @@ function tableTest() {
if (
!(response.body.message[0] as string).includes(
'is a LinkToAnotherRecord of',
'is a LinkToAnotherRecord of'
)
) {
throw new Error('Should give ltar foreign key error');
@ -1414,7 +1411,7 @@ function tableTest() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${row['CustomerId']}/exist`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${row['CustomerId']}/exist`
)
.set('xc-auth', context.token)
.expect(200);
@ -1427,7 +1424,7 @@ function tableTest() {
it('Exist should be false table row when it does not exists', async function () {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/998546/exist`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/998546/exist`
)
.set('xc-auth', context.token)
.expect(200);
@ -1534,7 +1531,7 @@ function tableTest() {
.patch(`/api/v1/db/data/bulk/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.send(
rows.map((row) => ({ title: `new-${row['Title']}`, id: row['Id'] })),
rows.map((row) => ({ title: `new-${row['Title']}`, id: row['Id'] }))
)
.expect(200);
const updatedRows: Array<any> = await listRow({ project, table });
@ -1615,7 +1612,7 @@ function tableTest() {
it('Export csv', async () => {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/export/csv`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/export/csv`
)
.set('xc-auth', context.token)
.expect(200);
@ -1634,14 +1631,14 @@ function tableTest() {
it('Export excel', async () => {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/export/excel`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/export/excel`
)
.set('xc-auth', context.token)
.expect(200);
if (
!response['header']['content-disposition'].includes(
'Customer-export.xlsx',
'Customer-export.xlsx'
)
) {
throw new Error('Wrong file name');
@ -1656,11 +1653,11 @@ function tableTest() {
it('Nested row list hm', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
@ -1675,11 +1672,11 @@ function tableTest() {
it('Nested row list hm with limit and offset', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`
)
.set('xc-auth', context.token)
.query({
@ -1701,11 +1698,11 @@ function tableTest() {
it('Row list hm with invalid table id', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/wrong-id/${rowId}/hm/${rentalListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/wrong-id/${rowId}/hm/${rentalListColumn.id}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1753,11 +1750,11 @@ function tableTest() {
});
const filmTable = await getTable({ project: sakilaProject, name: 'film' });
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
@ -1777,11 +1774,11 @@ function tableTest() {
});
const filmTable = await getTable({ project: sakilaProject, name: 'film' });
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.query({
@ -1808,11 +1805,11 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1826,12 +1823,12 @@ function tableTest() {
it('Create hm relation with invalid table id', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const refId = 1;
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/hm/${rentalListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/hm/${rentalListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1844,12 +1841,12 @@ function tableTest() {
it('Create hm relation with non ltar column', async () => {
const rowId = 1;
const firstNameColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'FirstName',
(column) => column.title === 'FirstName'
)!;
const refId = 1;
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${firstNameColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${firstNameColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1866,7 +1863,7 @@ function tableTest() {
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/invalid-column/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/invalid-column/${refId}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1901,20 +1898,20 @@ function tableTest() {
it('Create list hm', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const refId = 1;
const lisResponseBeforeUpdate = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(200);
@ -1922,7 +1919,7 @@ function tableTest() {
const lisResponseAfterUpdate = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
@ -1945,7 +1942,7 @@ function tableTest() {
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/invalid-column/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/invalid-column/${refId}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1965,12 +1962,12 @@ function tableTest() {
name: 'actor',
});
const firstNameColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'FirstName',
(column) => column.title === 'FirstName'
)!;
const refId = 1;
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${firstNameColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${firstNameColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(404);
@ -1988,13 +1985,13 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const refId = 1;
await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(400);
@ -2010,20 +2007,20 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const refId = 2;
const lisResponseBeforeUpdate = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(200);
@ -2031,7 +2028,7 @@ function tableTest() {
const lisResponseAfterUpdate = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
@ -2047,12 +2044,12 @@ function tableTest() {
it('List hm with non ltar column', async () => {
const rowId = 1;
const firstNameColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'FirstName',
(column) => column.title === 'FirstName'
)!;
await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${firstNameColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${firstNameColumn.id}`
)
.set('xc-auth', context.token)
.expect(400);
@ -2061,12 +2058,12 @@ function tableTest() {
it('List mm with non ltar column', async () => {
const rowId = 1;
const firstNameColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'FirstName',
(column) => column.title === 'FirstName'
)!;
await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/mm/${firstNameColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/mm/${firstNameColumn.id}`
)
.set('xc-auth', context.token)
.expect(400);
@ -2079,20 +2076,20 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const refId = 1;
const lisResponseBeforeDelete = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
await request(context.app)
.delete(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(200);
@ -2100,7 +2097,7 @@ function tableTest() {
const lisResponseAfterDelete = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);
@ -2119,13 +2116,13 @@ function tableTest() {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const refId = 76;
const response = await request(context.app)
.delete(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/${refId}`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/${refId}`
)
.set('xc-auth', context.token)
.expect(400);
@ -2133,7 +2130,7 @@ function tableTest() {
// todo: only keep generic error message once updated in noco catchError middleware
if (
!response.body.message?.includes(
"The column 'customer_id' cannot be null",
"The column 'customer_id' cannot be null"
) &&
!response.body.message?.includes("Column 'customer_id' cannot be null") &&
!response.body.message?.includes('Cannot add or update a child row') &&
@ -2142,7 +2139,7 @@ function tableTest() {
) {
console.log(
'Delete list hm with existing ref row id with non nullable clause',
response.body,
response.body
);
throw new Error('Wrong error message');
}
@ -2172,7 +2169,7 @@ function tableTest() {
const response = await request(context.app)
.delete(
`/api/v1/db/data/noco/${project.id}/${table.id}/${row['Id']}/hm/${ltarColumn.id}/${childRow['Id']}`,
`/api/v1/db/data/noco/${project.id}/${table.id}/${row['Id']}/hm/${ltarColumn.id}/${childRow['Id']}`
)
.set('xc-auth', context.token)
.expect(200);
@ -2183,9 +2180,7 @@ function tableTest() {
throw new Error('Was not deleted');
}
if (
response.body['msg'] !== 'The relation data has been deleted successfully'
) {
if (response.body['msg'] !== 'The relation data has been deleted successfully') {
throw new Error('Response incorrect');
}
});
@ -2193,12 +2188,12 @@ function tableTest() {
it('Exclude list hm', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.expect(200);
@ -2212,12 +2207,12 @@ function tableTest() {
it('Exclude list hm with limit and offset', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.query({
@ -2244,12 +2239,12 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.expect(200);
@ -2267,12 +2262,12 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.query({
@ -2299,12 +2294,12 @@ function tableTest() {
name: 'address',
});
const cityColumn = (await addressTable.getColumns()).find(
(column) => column.title === 'City',
(column) => column.title === 'City'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`
)
.set('xc-auth', context.token)
.expect(200);
@ -2320,12 +2315,12 @@ function tableTest() {
name: 'address',
});
const cityColumn = (await addressTable.getColumns()).find(
(column) => column.title === 'City',
(column) => column.title === 'City'
)!;
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`
)
.set('xc-auth', context.token)
.query({
@ -2341,12 +2336,12 @@ function tableTest() {
it('Create nested hm relation with invalid table id', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List',
(column) => column.title === 'Rental List'
)!;
const refId = 1;
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/hm/${rentalListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/hm/${rentalListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.expect(404);
@ -2364,11 +2359,11 @@ function tableTest() {
name: 'actor',
});
const filmListColumn = (await actorTable.getColumns()).find(
(column) => column.title === 'Film List',
(column) => column.title === 'Film List'
)!;
const response = await request(context.app)
.post(
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/mm/${filmListColumn.id}/exclude`,
`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/mm/${filmListColumn.id}/exclude`
)
.set('xc-auth', context.token)
.expect(404);
@ -2388,7 +2383,7 @@ function tableTest() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/Film/group/${ratingColumn.id}`,
`/api/v1/db/data/noco/${sakilaProject.id}/Film/group/${ratingColumn.id}`
)
.set('xc-auth', context.token)
.expect(200);

4704
tests/playwright/package-lock.json generated

File diff suppressed because it is too large Load Diff

3
tests/playwright/package.json

@ -11,7 +11,6 @@
"test:repeat": "TRACE=true npx playwright test --workers=4 --repeat-each=12",
"test:quick": "TRACE=true PW_QUICK_TEST=1 npx playwright test --workers=4",
"test:debug": "./startPlayWrightServer.sh; PW_TEST_REUSE_CONTEXT=1 PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:31000/ PWDEBUG=console npx playwright test -c playwright.config.ts --headed --project=chromium --retries 0 --timeout 0 --workers 1 --max-failures=1",
"test:debug:intelliJ": "TRACE=true PWDEBUG=console npx playwright test --trace on -c playwright.config.ts --headed --project=chromium --retries 0 --workers 1 --max-failures=1",
"test:debug:watch": "npx nodemon -e ts -w ./ -x \"npm run test:debug\"",
"test:debug:quick:sqlite": "./startPlayWrightServer.sh; PW_QUICK_TEST=1 PW_TEST_REUSE_CONTEXT=1 PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:31000/ PWDEBUG=console npx playwright test -c playwright.config.ts --headed --project=chromium --retries 0 --timeout 5 --workers 1 --max-failures=1",
"ci:test": "npx playwright test --workers=2",
@ -47,9 +46,7 @@
"body-parser": "^1.20.1",
"dayjs": "^1.11.7",
"express": "^4.18.2",
"knex": "^2.4.2",
"nocodb-sdk": "file:../../packages/nocodb-sdk",
"sqlite3": "^5.1.6",
"xlsx": "^0.18.5"
}
}

9
tests/playwright/pages/Dashboard/ExpandedForm/index.ts

@ -1,7 +1,6 @@
import { expect, Locator } from '@playwright/test';
import BasePage from '../../Base';
import { DashboardPage } from '..';
import { DateTimeCellPageObject } from '../common/Cell/DateTimeCell';
export class ExpandedFormPage extends BasePage {
readonly dashboard: DashboardPage;
@ -94,14 +93,6 @@ export class ExpandedFormPage extends BasePage {
await field.locator(`[data-testid="nc-child-list-button-link-to"]`).click();
await this.dashboard.linkRecord.select(value);
break;
case 'dateTime':
await field.locator('.nc-cell').click();
// eslint-disable-next-line no-case-declarations
const dateTimeObj = new DateTimeCellPageObject(this.dashboard.grid.cell);
await dateTimeObj.selectDate({ date: value.slice(0, 10) });
await dateTimeObj.selectTime({ hour: +value.slice(11, 13), minute: +value.slice(14, 16) });
await dateTimeObj.save();
break;
}
}

24
tests/playwright/pages/Dashboard/TreeView.ts

@ -48,24 +48,6 @@ export class TreeViewPage extends BasePage {
await this.get().locator(`.nc-project-tree-tbl-${title}`).focus();
}
async openBase({ title }: { title: string }) {
const nodes = await this.get().locator(`.ant-collapse`);
// loop through nodes.count() to find the node with title
for (let i = 0; i < (await nodes.count()); i++) {
const node = nodes.nth(i);
const nodeTitle = await node.innerText();
// check if nodeTitle contains title
if (nodeTitle.includes(title)) {
// click on node
await node.waitFor({ state: 'visible' });
await node.click();
break;
}
}
await this.rootPage.waitForTimeout(2000);
}
// assumption: first view rendered is always GRID
//
async openTable({
@ -90,8 +72,6 @@ export class TreeViewPage extends BasePage {
}
}
await this.get().locator(`.nc-project-tree-tbl-${title}`).waitFor({ state: 'visible' });
if (networkResponse === true) {
await this.waitForResponse({
uiAction: () => this.get().locator(`.nc-project-tree-tbl-${title}`).click(),
@ -106,7 +86,7 @@ export class TreeViewPage extends BasePage {
}
}
async createTable({ title, skipOpeningModal, mode }: { title: string; skipOpeningModal?: boolean; mode?: string }) {
async createTable({ title, skipOpeningModal }: { title: string; skipOpeningModal?: boolean }) {
if (!skipOpeningModal) await this.get().locator('.nc-add-new-table').click();
await this.dashboard.get().locator('.nc-modal-table-create').locator('.ant-modal-body').waitFor();
@ -121,7 +101,7 @@ export class TreeViewPage extends BasePage {
});
// Tab render is slow for playwright
await this.dashboard.waitForTabRender({ title, mode });
await this.dashboard.waitForTabRender({ title });
}
async verifyTable({ title, index, exists = true }: { title: string; index?: number; exists?: boolean }) {

29
tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts

@ -23,7 +23,7 @@ export class DateTimeCellPageObject extends BasePage {
}
async save() {
await this.rootPage.locator('button:has-text("Ok"):visible').click();
await this.rootPage.locator('button:has-text("Ok")').click();
}
async selectDate({
@ -36,15 +36,15 @@ export class DateTimeCellPageObject extends BasePage {
const [year, month, day] = date.split('-');
// configure year
await this.rootPage.locator('.ant-picker-year-btn:visible').click();
await this.rootPage.locator('.ant-picker-year-btn').click();
await this.rootPage.locator(`td[title="${year}"]`).click();
// configure month
await this.rootPage.locator('.ant-picker-month-btn:visible').click();
await this.rootPage.locator('.ant-picker-month-btn').click();
await this.rootPage.locator(`td[title="${year}-${month}"]`).click();
// configure day
await this.rootPage.locator(`td[title="${year}-${month}-${day}"]:visible`).click();
await this.rootPage.locator(`td[title="${year}-${month}-${day}"]`).click();
}
async selectTime({
@ -60,20 +60,14 @@ export class DateTimeCellPageObject extends BasePage {
second?: number | null;
}) {
await this.rootPage
.locator(
`.ant-picker-time-panel-column:nth-child(1) > .ant-picker-time-panel-cell:nth-child(${hour + 1}):visible`
)
.locator(`.ant-picker-time-panel-column:nth-child(1) > .ant-picker-time-panel-cell:nth-child(${hour + 1})`)
.click();
await this.rootPage
.locator(
`.ant-picker-time-panel-column:nth-child(2) > .ant-picker-time-panel-cell:nth-child(${minute + 1}):visible`
)
.locator(`.ant-picker-time-panel-column:nth-child(2) > .ant-picker-time-panel-cell:nth-child(${minute + 1})`)
.click();
if (second != null) {
await this.rootPage
.locator(
`.ant-picker-time-panel-column:nth-child(3) > .ant-picker-time-panel-cell:nth-child(${second + 1}):visible`
)
.locator(`.ant-picker-time-panel-column:nth-child(3) > .ant-picker-time-panel-cell:nth-child(${second + 1})`)
.click();
}
}
@ -81,13 +75,4 @@ export class DateTimeCellPageObject extends BasePage {
async close() {
await this.rootPage.keyboard.press('Escape');
}
async setDateTime({ index, columnHeader, dateTime }: { index: number; columnHeader: string; dateTime: string }) {
const [date, time] = dateTime.split(' ');
const [hour, minute, second] = time.split(':');
await this.open({ index, columnHeader });
await this.selectDate({ date });
await this.selectTime({ hour: +hour, minute: +minute });
await this.save();
}
}

14
tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts

@ -118,7 +118,7 @@ export class SelectOptionCellPageObject extends BasePage {
index,
columnHeader,
option,
multiSelect,
multiSelect = false,
}: {
index: number;
columnHeader: string;
@ -134,10 +134,18 @@ export class SelectOptionCellPageObject extends BasePage {
await selectCell.locator('.ant-select-selection-search-input').type(option);
await selectCell.locator('.ant-select-selection-search-input').press('Enter');
// await selectCell.locator('.ant-select-selection-search-input').press('Enter');
// Wait for update api call
const saveRowAction = () => selectCell.locator('.ant-select-selection-search-input').press('Enter');
await this.waitForResponse({
uiAction: saveRowAction,
requestUrlPathToMatch: 'api/v1/db/data/noco/',
httpMethodsToMatch: ['PATCH'],
responseJsonMatcher: resJson => String(resJson?.[columnHeader]).includes(String(option)),
});
if (multiSelect) await selectCell.locator('.ant-select-selection-search-input').press('Escape');
// todo: wait for update api call
}
async verifySelectedOptions({

8
tests/playwright/pages/Dashboard/common/Cell/index.ts

@ -360,12 +360,4 @@ export class CellPageObject extends BasePage {
await this.get({ index, columnHeader }).press((await this.isMacOs()) ? 'Meta+C' : 'Control+C');
await this.verifyToast({ message: 'Copied to clipboard' });
}
async pasteFromClipboard({ index, columnHeader }: CellProps, ...clickOptions: Parameters<Locator['click']>) {
await this.get({ index, columnHeader }).scrollIntoViewIfNeeded();
await this.get({ index, columnHeader }).click(...clickOptions);
await (await this.get({ index, columnHeader }).elementHandle()).waitForElementState('stable');
await this.get({ index, columnHeader }).press((await this.isMacOs()) ? 'Meta+V' : 'Control+V');
}
}

1
tests/playwright/pages/Dashboard/common/Toolbar/index.ts

@ -66,6 +66,7 @@ export class ToolbarPage extends BasePage {
// Wait for the menu to close
if (menuOpen) await this.fields.get().waitFor({ state: 'hidden' });
else await this.fields.get().waitFor({ state: 'visible' });
}
async clickFindRowByScanButton() {

950
tests/playwright/tests/db/timezone.spec.ts

@ -1,950 +0,0 @@
import { expect, test } from '@playwright/test';
import { DashboardPage } from '../../pages/Dashboard';
import setup from '../../setup';
import { knex } from 'knex';
import { Api, UITypes } from 'nocodb-sdk';
import { ProjectsPage } from '../../pages/ProjectsPage';
import { isMysql, isPg, isSqlite } from '../../setup/db';
import { getKnexConfig } from '../utils/config';
let api: Api<any>, records: any[];
const columns = [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
ai: 1,
pk: 1,
},
{
column_name: 'DateTime',
title: 'DateTime',
uidt: UITypes.DateTime,
},
];
const rowAttributes = [
{ Id: 1, DateTime: '2021-01-01 00:00:00' },
{ Id: 2, DateTime: '2021-01-01 04:00:00+04:00' },
{ Id: 3, DateTime: '2020-12-31 20:00:00-04:00' },
];
async function timezoneSuite(token?: string, skipTableCreate?: boolean) {
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': token,
},
});
const projectList = await api.project.list();
for (const project of projectList.list) {
// delete project with title 'xcdb' if it exists
if (project.title === 'xcdb') {
await api.project.delete(project.id);
}
}
const project = await api.project.create({ title: 'xcdb' });
if (skipTableCreate) return { project };
const table = await api.base.tableCreate(project.id, project.bases?.[0].id, {
table_name: 'dateTimeTable',
title: 'dateTimeTable',
columns: columns,
});
return { project, table };
}
async function connectToExtDb(context: any) {
if (isPg(context)) {
await api.base.create(context.project.id, {
alias: 'datetimetable',
type: 'pg',
config: getKnexConfig({ dbName: 'datetimetable', dbType: 'pg' }),
inflection_column: 'camelize',
inflection_table: 'camelize',
});
} else if (isMysql(context)) {
await api.base.create(context.project.id, {
alias: 'datetimetable',
type: 'mysql2',
config: getKnexConfig({ dbName: 'datetimetable', dbType: 'mysql' }),
inflection_column: 'camelize',
inflection_table: 'camelize',
});
} else if (isSqlite(context)) {
await api.base.create(context.project.id, {
alias: 'datetimetable',
type: 'sqlite3',
config: {
client: 'sqlite3',
connection: {
client: 'sqlite3',
database: 'datetimetable',
connection: {
filename: '../../tests/playwright/mydb.sqlite3',
},
useNullAsDefault: true,
},
},
inflection_column: 'camelize',
inflection_table: 'camelize',
});
}
}
test.describe('Timezone : Japan/Tokyo', () => {
let dashboard: DashboardPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.project);
if (!isSqlite(context)) return;
try {
const { project, table } = await timezoneSuite(context.token);
await api.dbTableRow.bulkCreate('noco', project.id, table.id, rowAttributes);
records = await api.dbTableRow.list('noco', project.id, table.id, { limit: 10 });
} catch (e) {
console.error(e);
}
await page.reload();
});
// DST independent test
test.use({
locale: 'ja-JP', // Change to Japanese locale
timezoneId: 'Asia/Tokyo', // Set timezone to Tokyo timezone
});
/*
* This test is to verify the display value of DateTime column in the grid
* when the timezone is set to Asia/Tokyo
*
* The test inserts 3 rows using API
* 1. DateTime inserted without timezone
* 2. DateTime inserted with timezone (UTC+4)
* 3. DateTime inserted with timezone (UTC-4)
*
* Expected display values:
* Display value is converted to Asia/Tokyo
*/
test('API insert, verify display value', async () => {
if (!isSqlite(context)) return;
await dashboard.clickHome();
const projectsPage = new ProjectsPage(dashboard.rootPage);
await projectsPage.openProject({ title: 'xcdb', withoutPrefix: true });
await dashboard.treeView.openTable({ title: 'dateTimeTable' });
// DateTime inserted using API without timezone is converted to UTC
// Display value is converted to Asia/Tokyo
await dashboard.grid.cell.verifyDateCell({ index: 0, columnHeader: 'DateTime', value: '2021-01-01 09:00' });
// DateTime inserted using API with timezone is converted to UTC
// Display value is converted to Asia/Tokyo
await dashboard.grid.cell.verifyDateCell({ index: 1, columnHeader: 'DateTime', value: '2021-01-01 09:00' });
await dashboard.grid.cell.verifyDateCell({ index: 2, columnHeader: 'DateTime', value: '2021-01-01 09:00' });
});
/*
* This test is to verify the API read response of DateTime column
* when the timezone is set to Asia/Tokyo
*
* The test inserts 3 rows using API
* 1. DateTime inserted without timezone
* 2. DateTime inserted with timezone (UTC+4)
* 3. DateTime inserted with timezone (UTC-4)
*
* Expected API response:
* API response is in UTC
*/
test('API Insert, verify API read response', async () => {
if (!isSqlite(context)) return;
// UTC expected response
const dateUTC = ['2021-01-01 00:00:00+00:00', '2021-01-01 00:00:00+00:00', '2021-01-01 00:00:00+00:00'];
const readDate = records.list.map(record => record.DateTime);
// expect API response to be in UTC
expect(readDate).toEqual(dateUTC);
});
});
// Change browser timezone & locale to Asia/Hong-Kong
//
test.describe('Timezone : Asia/Hong-kong', () => {
let dashboard: DashboardPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.project);
try {
const { project, table } = await timezoneSuite(context.token);
await api.dbTableRow.bulkCreate('noco', project.id, table.id, rowAttributes);
} catch (e) {
console.error(e);
}
await page.reload();
});
test.use({
locale: 'zh-HK',
timezoneId: 'Asia/Hong_Kong',
});
/*
* This test is to verify the display value of DateTime column in the grid
* when the timezone is set to Asia/Hong-Kong
*
* The test inserts 3 rows using API
* 1. DateTime inserted without timezone
* 2. DateTime inserted with timezone (UTC+4)
* 3. DateTime inserted with timezone (UTC-4)
*
* Expected display values:
* Display value is converted to Asia/Hong-Kong
*/
test('API inserted, verify display value', async () => {
await dashboard.clickHome();
const projectsPage = new ProjectsPage(dashboard.rootPage);
await projectsPage.openProject({ title: 'xcdb', withoutPrefix: true });
await dashboard.treeView.openTable({ title: 'dateTimeTable' });
// DateTime inserted using API without timezone is converted to UTC
// Display value is converted to Asia/Hong_Kong
await dashboard.grid.cell.verifyDateCell({ index: 0, columnHeader: 'DateTime', value: '2021-01-01 08:00' });
// DateTime inserted using API with timezone is converted to UTC
// Display value is converted to Asia/Hong_Kong
await dashboard.grid.cell.verifyDateCell({ index: 1, columnHeader: 'DateTime', value: '2021-01-01 08:00' });
await dashboard.grid.cell.verifyDateCell({ index: 2, columnHeader: 'DateTime', value: '2021-01-01 08:00' });
});
});
test.describe('Timezone', () => {
let dashboard: DashboardPage;
let context: any;
test.use({
locale: 'zh-HK',
timezoneId: 'Asia/Hong_Kong',
});
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.project);
if (!isSqlite(context)) return;
const { project } = await timezoneSuite(context.token, true);
context.project = project;
// Using API for test preparation was not working
// Hence switched over to UI based table creation
await dashboard.clickHome();
const projectsPage = new ProjectsPage(dashboard.rootPage);
await projectsPage.openProject({ title: 'xcdb', withoutPrefix: true });
await dashboard.treeView.createTable({ title: 'dateTimeTable', mode: 'Xcdb' });
await dashboard.grid.column.create({
title: 'DateTime',
type: 'DateTime',
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm',
});
await dashboard.grid.cell.dateTime.setDateTime({
index: 0,
columnHeader: 'DateTime',
dateTime: '2021-01-01 08:00:00',
});
// await dashboard.rootPage.reload();
});
/*
* This test is to verify the display value & API response of DateTime column in the grid
* when the value inserted is from the UI
*
* Note: Timezone for this test is set as Asia/Hong-Kong
*
* 1. Create table with DateTime column
* 2. Insert DateTime value from UI '2021-01-01 08:00:00'
* 3. Verify display value : should be '2021-01-01 08:00:00'
* 4. Verify API response, expect UTC : should be '2021-01-01 00:00:00'
*
*/
test('Cell insert', async () => {
if (!isSqlite(context)) return;
// Verify stored value in database is UTC
records = await api.dbTableRow.list('noco', context.project.id, 'dateTimeTable', { limit: 10 });
const readDate = records.list[0].DateTime;
// skip seconds from readDate
// stored value expected to be in UTC
expect(readDate.slice(0, 16)).toEqual('2021-01-01 00:00');
// DateTime inserted from cell is converted to UTC & stored
// Display value is same as inserted value
await dashboard.grid.cell.verifyDateCell({ index: 0, columnHeader: 'DateTime', value: '2021-01-01 08:00' });
});
/*
* This test is to verify the display value & API response of DateTime column in the grid
* when the value inserted is from expanded record
*
* Note: Timezone for this test is set as Asia/Hong-Kong
*
* 1. Create table with DateTime column
* 2. Insert DateTime value from UI '2021-01-01 08:00:00'
* 3. Expand record & update DateTime value to '2021-02-02 12:30:00'
* 4. Verify display value : should be '2021-02-02 12:30:00'
* 5. Verify API response, expect UTC : should be '2021-02-02 04:30:00'
*
*/
test('Expanded record insert', async () => {
if (!isSqlite(context)) return;
await dashboard.grid.openExpandedRow({ index: 0 });
await dashboard.expandedForm.fillField({
columnTitle: 'DateTime',
value: '2021-02-02 12:30:00',
type: 'dateTime',
});
await dashboard.expandedForm.save();
records = await api.dbTableRow.list('noco', context.project.id, 'dateTimeTable', { limit: 10 });
const readDate = records.list[0].DateTime;
// skip seconds from readDate
// stored value expected to be in UTC
expect(readDate.slice(0, 16)).toEqual('2021-02-02 04:30');
// DateTime inserted from cell is converted to UTC & stored
// Display value is same as inserted value
await dashboard.grid.cell.verifyDateCell({ index: 0, columnHeader: 'DateTime', value: '2021-02-02 12:30' });
});
/*
* This test is to verify the display value & API response of DateTime column in the grid
* when the value inserted is from copy and paste
*
* Note: Timezone for this test is set as Asia/Hong-Kong
*
* 1. Create table with DateTime column
* 2. Insert DateTime value from UI '2021-01-01 08:00:00'
* 3. Add new row & copy and paste DateTime value to '2021-01-01 08:00:00'
* 4. Verify display value : should be '2021-01-01 08:00:00'
* 5. Verify API response, expect UTC : should be '2021-01-01 00:00:00'
*
*/
test('Copy paste', async () => {
if (!isSqlite(context)) return;
await dashboard.grid.addNewRow({ index: 1, columnHeader: 'Title', value: 'Copy paste test' });
await dashboard.rootPage.reload();
await dashboard.rootPage.waitForTimeout(1000);
await dashboard.grid.cell.copyToClipboard(
{
index: 0,
columnHeader: 'DateTime',
},
{ position: { x: 1, y: 1 } }
);
expect(await dashboard.grid.cell.getClipboardText()).toBe('2021-01-01 08:00');
await dashboard.grid.cell.pasteFromClipboard({ index: 1, columnHeader: 'DateTime' });
records = await api.dbTableRow.list('noco', context.project.id, 'dateTimeTable', { limit: 10 });
const readDate = records.list[1].DateTime;
// skip seconds from readDate
// stored value expected to be in UTC
expect(readDate.slice(0, 16)).toEqual('2021-01-01 00:00');
// DateTime inserted from cell is converted to UTC & stored
// Display value is same as inserted value
await dashboard.grid.cell.verifyDateCell({ index: 1, columnHeader: 'DateTime', value: '2021-01-01 08:00' });
});
});
async function createTableWithDateTimeColumn(database: string, setTz = false) {
if (database === 'pg') {
const config = getKnexConfig({ dbName: 'postgres', dbType: 'pg' });
const pgknex = knex(config);
await pgknex.raw(`DROP DATABASE IF EXISTS datetimetable`);
await pgknex.raw(`CREATE DATABASE datetimetable`);
await pgknex.destroy();
const config2 = getKnexConfig({ dbName: 'datetimetable', dbType: 'pg' });
const pgknex2 = knex(config2);
await pgknex2.raw(`
CREATE TABLE my_table (
title SERIAL PRIMARY KEY,
datetime_without_tz TIMESTAMP WITHOUT TIME ZONE,
datetime_with_tz TIMESTAMP WITH TIME ZONE
);
-- SET timezone = 'Asia/Hong_Kong';
-- SELECT pg_sleep(1);
INSERT INTO my_table (datetime_without_tz, datetime_with_tz)
VALUES
('2023-04-27 10:00:00', '2023-04-27 10:00:00'),
('2023-04-27 10:00:00+05:30', '2023-04-27 10:00:00+05:30');
`);
await pgknex2.destroy();
} else if (database === 'mysql') {
const config = getKnexConfig({ dbName: 'sakila', dbType: 'mysql' });
const mysqlknex = knex(config);
await mysqlknex.raw(`DROP DATABASE IF EXISTS datetimetable`);
await mysqlknex.raw(`CREATE DATABASE datetimetable`);
if (setTz) {
await mysqlknex.raw(`SET GLOBAL time_zone = '+08:00'`);
// wait for 1 second for the timezone to be set
await mysqlknex.raw(`SELECT SLEEP(1)`);
}
await mysqlknex.destroy();
const config2 = getKnexConfig({ dbName: 'datetimetable', dbType: 'mysql' });
const mysqlknex2 = knex(config2);
await mysqlknex2.raw(`
USE datetimetable;
CREATE TABLE my_table (
title INT AUTO_INCREMENT PRIMARY KEY,
datetime_without_tz DATETIME,
datetime_with_tz TIMESTAMP
);
INSERT INTO my_table (datetime_without_tz, datetime_with_tz)
VALUES
('2023-04-27 10:00:00', '2023-04-27 10:00:00'),
('2023-04-27 10:00:00+05:30', '2023-04-27 10:00:00+05:30');
`);
await mysqlknex2.destroy();
} else if (database === 'sqlite') {
const config = getKnexConfig({ dbName: 'mydb', dbType: 'sqlite' });
// SQLite supports just one type of datetime
// Timezone information, if specified is stored as is in the database
// https://www.sqlite.org/lang_datefunc.html
const sqliteknex = knex(config);
await sqliteknex.raw(`DROP TABLE IF EXISTS my_table`);
await sqliteknex.raw(`
CREATE TABLE my_table (
title INTEGER PRIMARY KEY AUTOINCREMENT,
datetime_without_tz DATETIME,
datetime_with_tz DATETIME )`);
const datetimeData = [
['2023-04-27 10:00:00', '2023-04-27 10:00:00'],
['2023-04-27 10:00:00+05:30', '2023-04-27 10:00:00+05:30'],
];
for (const data of datetimeData) {
await sqliteknex('my_table').insert({
datetime_without_tz: data[0],
datetime_with_tz: data[1],
});
}
await sqliteknex.destroy();
}
}
function getDateTimeInLocalTimeZone(dateString: string) {
// create a Date object with the input string
// assumes local system timezone
const date = new Date(dateString);
// get the timezone offset in minutes and convert to milliseconds
// subtract the offset from the provided time in milliseconds for IST
const offsetMs = date.getTimezoneOffset() * 60 * 1000;
// adjust the date by the offset
const adjustedDate = new Date(date.getTime() - offsetMs);
// format the adjusted date as a string in the desired format
const outputString = adjustedDate.toISOString().slice(0, 16).replace('T', ' ');
// output the result
return outputString;
}
function getDateTimeInUTCTimeZone(dateString: string) {
// create a Date object with the input string
const date = new Date(dateString);
// get the timezone offset in minutes and convert to milliseconds
// subtract the offset from the provided time in milliseconds for IST
// const offsetMs = date.getTimezoneOffset() * 60 * 1000;
// adjust the date by the offset
// const adjustedDate = new Date(date.getTime() + offsetMs);
const adjustedDate = new Date(date.getTime());
// format the adjusted date as a string in the desired format
const outputString = adjustedDate.toISOString().slice(0, 19).replace('T', ' ');
// output the result
return `${outputString}+00:00`;
}
test.describe.serial('External DB - DateTime column', async () => {
let dashboard: DashboardPage;
let context: any;
const expectedDisplayValues = {
pg: {
// PG ignores timezone information for datetime without timezone
DatetimeWithoutTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
],
// PG stores datetime with timezone information in UTC
DatetimeWithTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
],
},
sqlite: {
// without +HH:MM information, display value is same as inserted value
// with +HH:MM information, display value is converted to browser timezone
// SQLite doesn't have with & without timezone fields; both are same in this case
DatetimeWithoutTz: [
getDateTimeInLocalTimeZone(`2023-04-27 10:00:00`),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
],
DatetimeWithTz: [
getDateTimeInLocalTimeZone(`2023-04-27 10:00:00`),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
],
},
mysql: {
DatetimeWithoutTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
],
DatetimeWithTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
],
},
};
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.project);
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
await createTableWithDateTimeColumn(context.dbType);
});
test('Formula, verify display value', async () => {
await connectToExtDb(context);
await dashboard.rootPage.reload();
await dashboard.rootPage.waitForTimeout(2000);
// insert a record to work with formula experiments
//
await dashboard.treeView.openBase({ title: 'datetimetable' });
await dashboard.treeView.openTable({ title: 'MyTable' });
// Insert new row
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithoutTz',
dateTime: '2023-04-27 10:00:00',
});
await dashboard.rootPage.waitForTimeout(1000);
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithTz',
dateTime: '2023-04-27 10:00:00',
});
// Create formula column (dummy)
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
const table = await api.dbTable.list(context.project.id);
let table_data: any;
table_data = await api.dbTableColumn.create(table.list.find(x => x.title === 'MyTable').id, {
title: 'formula-1',
uidt: UITypes.Formula,
formula_raw: '0',
});
table_data = await api.dbTableColumn.create(table.list.find(x => x.title === 'MyTable').id, {
title: 'formula-2',
uidt: UITypes.Formula,
formula_raw: '0',
});
async function verifyFormula({
formula,
expectedDisplayValue,
}: {
formula: string[];
expectedDisplayValue: string[];
}) {
// Update formula column to compute "month" instead of "day"
await api.dbTableColumn.update(table_data.columns[3].id, {
title: 'formula-1',
column_name: 'formula-1',
uidt: UITypes.Formula,
formula_raw: formula[0],
});
await dashboard.rootPage.waitForTimeout(1000);
await api.dbTableColumn.update(table_data.columns[4].id, {
title: 'formula-2',
column_name: 'formula-2',
uidt: UITypes.Formula,
formula_raw: formula[1],
});
// reload page
await dashboard.rootPage.reload();
await dashboard.grid.cell.verify({
index: 2,
columnHeader: 'formula-1',
value: expectedDisplayValue[0],
});
await dashboard.grid.cell.verify({
index: 2,
columnHeader: 'formula-2',
value: expectedDisplayValue[1],
});
}
// verify display value for formula columns (formula-1, formula-2)
await verifyFormula({
formula: ['DATEADD(DatetimeWithoutTz, 1, "day")', 'DATEADD(DatetimeWithTz, 1, "day")'],
expectedDisplayValue: ['2023-04-28 10:00', '2023-04-28 10:00'],
});
await verifyFormula({
formula: ['DATEADD(DatetimeWithoutTz, 1, "month")', 'DATEADD(DatetimeWithTz, 1, "month")'],
expectedDisplayValue: ['2023-05-27 10:00', '2023-05-27 10:00'],
});
await verifyFormula({
formula: ['DATEADD(DatetimeWithoutTz, 1, "year")', 'DATEADD(DatetimeWithTz, 1, "year")'],
expectedDisplayValue: ['2024-04-27 10:00', '2024-04-27 10:00'],
});
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithTz',
dateTime: '2024-04-27 10:00:00',
});
if (!isSqlite(context)) {
// SQLite : output is in decimal format; MySQL & Postgres : output is in integer format
await verifyFormula({
formula: [
'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "days")',
'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "days")',
],
expectedDisplayValue: ['-366', '366'],
});
await verifyFormula({
formula: [
'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "months")',
'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "months")',
],
expectedDisplayValue: ['-12', '12'],
});
}
});
test('Verify display value, UI insert, API response', async () => {
await connectToExtDb(context);
await dashboard.rootPage.reload();
await dashboard.rootPage.waitForTimeout(2000);
// get timezone offset
const timezoneOffset = new Date().getTimezoneOffset();
const hours = Math.floor(Math.abs(timezoneOffset) / 60);
const minutes = Math.abs(timezoneOffset % 60);
const sign = timezoneOffset <= 0 ? '+' : '-';
const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
await dashboard.treeView.openBase({ title: 'datetimetable' });
await dashboard.treeView.openTable({ title: 'MyTable' });
if (isSqlite(context)) {
expectedDisplayValues['sqlite'].DatetimeWithoutTz[0] = getDateTimeInLocalTimeZone(
`2023-04-27 10:00:00${formattedOffset}`
);
expectedDisplayValues['sqlite'].DatetimeWithTz[0] = getDateTimeInLocalTimeZone(
`2023-04-27 10:00:00${formattedOffset}`
);
}
// display value for datetime column without tz should be same as stored value
// display value for datetime column with tz should be converted to browser timezone (HK in this case)
await dashboard.grid.cell.verifyDateCell({
index: 0,
columnHeader: 'DatetimeWithoutTz',
value: expectedDisplayValues[context.dbType].DatetimeWithoutTz[0],
});
await dashboard.grid.cell.verifyDateCell({
index: 1,
columnHeader: 'DatetimeWithoutTz',
value: expectedDisplayValues[context.dbType].DatetimeWithoutTz[1],
});
await dashboard.grid.cell.verifyDateCell({
index: 0,
columnHeader: 'DatetimeWithTz',
value: expectedDisplayValues[context.dbType].DatetimeWithTz[0],
});
await dashboard.grid.cell.verifyDateCell({
index: 1,
columnHeader: 'DatetimeWithTz',
value: expectedDisplayValues[context.dbType].DatetimeWithTz[1],
});
// Insert new row
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithoutTz',
dateTime: '2023-04-27 10:00:00',
});
await dashboard.rootPage.waitForTimeout(1000);
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithTz',
dateTime: '2023-04-27 10:00:00',
});
// reload page & verify if inserted values are shown correctly
await dashboard.rootPage.reload();
await dashboard.grid.cell.verifyDateCell({
index: 2,
columnHeader: 'DatetimeWithoutTz',
value: '2023-04-27 10:00',
});
await dashboard.grid.cell.verifyDateCell({
index: 2,
columnHeader: 'DatetimeWithTz',
value: '2023-04-27 10:00',
});
// verify API response
// Note that, for UI inserted records - second part of datetime may be non-zero (though not shown in UI)
// Hence, we skip seconds from API response
//
const records = await api.dbTableRow.list('noco', context.project.id, 'MyTable', { limit: 10 });
let dateTimeWithoutTz = records.list.map(record => record.DatetimeWithoutTz);
let dateTimeWithTz = records.list.map(record => record.DatetimeWithTz);
let expectedDateTimeWithoutTz = [];
let expectedDateTimeWithTz = [];
if (isSqlite(context)) {
expectedDateTimeWithoutTz = [
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+05:30'),
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
expectedDateTimeWithTz = [
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+05:30'),
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
} else if (isPg(context)) {
expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00+00:00',
'2023-04-27 10:00:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
expectedDateTimeWithTz = [
'2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
} else if (isMysql(context)) {
expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
expectedDateTimeWithTz = [
'2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
}
// reset seconds to 00 using string functions in dateTimeWithoutTz
dateTimeWithoutTz = dateTimeWithoutTz.map(
dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
);
dateTimeWithTz = dateTimeWithTz.map(
dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
);
console.log('dateTimeWithoutTz', dateTimeWithoutTz);
console.log('dateTimeWithTz', dateTimeWithTz);
expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz);
expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz);
});
});
test.describe('Ext DB MySQL : DB Timezone configured as HKT', () => {
let dashboard: DashboardPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.project);
if (!isMysql(context)) {
return;
}
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
await createTableWithDateTimeColumn(context.dbType, true);
});
test.afterEach(async () => {
if (isMysql(context)) {
// Reset DB Timezone
const config = getKnexConfig({ dbName: 'sakila', dbType: 'mysql' });
const mysqlknex = knex(config);
await mysqlknex.raw(`SET GLOBAL time_zone = '+00:00'`);
await mysqlknex.destroy();
}
});
test('Ext DB MySQL : DB Timezone configured as HKT', async () => {
if (!isMysql(context)) {
return;
}
// get timezone offset
const timezoneOffset = new Date().getTimezoneOffset();
const hours = Math.floor(Math.abs(timezoneOffset) / 60);
const minutes = Math.abs(timezoneOffset % 60);
const sign = timezoneOffset <= 0 ? '+' : '-';
const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
// connect after timezone is set
await connectToExtDb(context);
await dashboard.rootPage.reload();
await dashboard.rootPage.waitForTimeout(2000);
await dashboard.treeView.openBase({ title: 'datetimetable' });
await dashboard.treeView.openTable({ title: 'MyTable' });
// display value for datetime column without tz should be same as stored value
// display value for datetime column with tz should be converted to browser timezone (HK in this case)
await dashboard.grid.cell.verifyDateCell({
index: 0,
columnHeader: 'DatetimeWithoutTz',
value: getDateTimeInLocalTimeZone('2023-04-27 10:00+08:00'),
});
await dashboard.grid.cell.verifyDateCell({
index: 1,
columnHeader: 'DatetimeWithoutTz',
value: getDateTimeInLocalTimeZone('2023-04-27 10:00+05:30'),
});
await dashboard.grid.cell.verifyDateCell({
index: 0,
columnHeader: 'DatetimeWithTz',
value: getDateTimeInLocalTimeZone('2023-04-27 10:00+08:00'),
});
await dashboard.grid.cell.verifyDateCell({
index: 1,
columnHeader: 'DatetimeWithTz',
value: getDateTimeInLocalTimeZone('2023-04-27 10:00+05:30'),
});
// Insert new row
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithoutTz',
dateTime: '2023-04-27 10:00:00',
});
await dashboard.grid.cell.dateTime.setDateTime({
index: 2,
columnHeader: 'DatetimeWithTz',
dateTime: '2023-04-27 10:00:00',
});
// reload page & verify if inserted values are shown correctly
await dashboard.rootPage.reload();
await dashboard.grid.cell.verifyDateCell({
index: 2,
columnHeader: 'DatetimeWithoutTz',
value: '2023-04-27 10:00',
});
await dashboard.grid.cell.verifyDateCell({
index: 2,
columnHeader: 'DatetimeWithTz',
value: '2023-04-27 10:00',
});
// verify API response
// Note that, for UI inserted records - second part of datetime may be non-zero (though not shown in UI)
// Hence, we skip seconds from API response
//
const records = await api.dbTableRow.list('sakila', context.project.id, 'MyTable', { limit: 10 });
let dateTimeWithoutTz = records.list.map(record => record.DatetimeWithoutTz);
let dateTimeWithTz = records.list.map(record => record.DatetimeWithTz);
const expectedDateTimeWithoutTz = [
'2023-04-27 02:00:00+00:00',
'2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
const expectedDateTimeWithTz = [
'2023-04-27 02:00:00+00:00',
'2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
];
// reset seconds to 00 using string functions in dateTimeWithoutTz
dateTimeWithoutTz = dateTimeWithoutTz.map(
dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
);
dateTimeWithTz = dateTimeWithTz.map(
dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
);
console.log('dateTimeWithoutTz', dateTimeWithoutTz);
console.log('dateTimeWithTz', dateTimeWithTz);
expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz);
expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz);
});
});

4
tests/playwright/tests/db/undo-redo.spec.ts

@ -178,6 +178,10 @@ test.describe('Undo Redo', () => {
await dashboard.closeTab({ title: 'Team & Auth' });
await dashboard.treeView.openTable({ title: 'numberBased' });
// hack: wait for grid to load
// https://github.com/nocodb/nocodb/actions/runs/5025773509/jobs/9013176970
await page.waitForTimeout(1000);
await verifyFieldsOrder(['Number', 'Decimal', 'Currency']);
// Hide Decimal

2
tests/playwright/tests/db/viewGridShare.spec.ts

@ -83,7 +83,7 @@ test.describe('Shared view', () => {
}
const expectedRecordsByDb = isSqlite(context) || isPg(context) ? sqliteExpectedRecords : expectedRecords;
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 1000));
// verify order of records (original sort & filter)
for (const record of expectedRecordsByDb) {
await sharedPage.grid.cell.verify(record);

48
tests/playwright/tests/utils/config.ts

@ -1,48 +0,0 @@
const knexConfig = {
pg: {
client: 'pg',
connection: {
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'password',
database: 'postgres',
multipleStatements: true,
},
searchPath: ['public', 'information_schema'],
pool: { min: 0, max: 5 },
},
mysql: {
client: 'mysql2',
connection: {
host: 'localhost',
port: 3306,
user: 'root',
password: 'password',
database: 'sakila',
multipleStatements: true,
},
pool: { min: 0, max: 5 },
},
sqlite: {
client: 'sqlite3',
connection: {
filename: './mydb.sqlite3',
},
useNullAsDefault: true,
pool: { min: 0, max: 5 },
},
};
function getKnexConfig({ dbName, dbType }: { dbName: string; dbType: string }) {
const config = knexConfig[dbType];
if (dbType === 'sqlite') {
config.connection.filename = `./${dbName}.sqlite3`;
return config;
}
config.connection.database = dbName;
return config;
}
export { getKnexConfig };
Loading…
Cancel
Save