mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix(database): fix test cases (#6811)
* fix(database): fix test cases * fix(database): fix unique and null
This commit is contained in:
parent
fd8606e69e
commit
15bb8ac97b
@ -115,9 +115,7 @@ describe('string field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: ' n1\n ',
|
name: ' n1\n ',
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBe('n1');
|
||||||
name: 'n1',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('trim when value is null should be null', async () => {
|
it('trim when value is null should be null', async () => {
|
||||||
@ -129,9 +127,7 @@ describe('string field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: null,
|
name: null,
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBeFalsy();
|
||||||
name: null,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('when value is number should be convert to string', async () => {
|
it('when value is number should be convert to string', async () => {
|
||||||
@ -143,8 +139,6 @@ describe('string field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: 123,
|
name: 123,
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBe('123');
|
||||||
name: '123',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -62,9 +62,7 @@ describe('text field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: ' n1\n ',
|
name: ' n1\n ',
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBe('n1');
|
||||||
name: 'n1',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('trim when value is null should be null', async () => {
|
it('trim when value is null should be null', async () => {
|
||||||
@ -76,9 +74,7 @@ describe('text field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: null,
|
name: null,
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBeFalsy();
|
||||||
name: null,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('when value is number should be convert to string', async () => {
|
it('when value is number should be convert to string', async () => {
|
||||||
@ -90,8 +86,6 @@ describe('text field', () => {
|
|||||||
const model = await collection.model.create({
|
const model = await collection.model.create({
|
||||||
name: 123,
|
name: 123,
|
||||||
});
|
});
|
||||||
expect(model.toJSON()).toMatchObject({
|
expect(model.get('name')).toBe('123');
|
||||||
name: '123',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,12 +20,16 @@ export class StringField extends Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
additionalSequelizeOptions() {
|
additionalSequelizeOptions() {
|
||||||
const { name, trim } = this.options;
|
const { name, trim, unique } = this.options;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (unique && value === '') {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return value;
|
this.setDataValue(name, null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
|
@ -25,12 +25,16 @@ export class TextField extends Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
additionalSequelizeOptions() {
|
additionalSequelizeOptions() {
|
||||||
const { name, trim } = this.options;
|
const { name, trim, unique } = this.options;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (unique && value === '') {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return value;
|
this.setDataValue(name, null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user