Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
b7413ee6
Commit
b7413ee6
authored
Jul 15, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit tests
parent
061028cf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
5 deletions
+53
-5
index.ts
index.ts
+2
-0
src/bases/id-base.ts
src/bases/id-base.ts
+1
-1
src/bases/time-base.ts
src/bases/time-base.ts
+3
-1
tests/sample.spec.ts
tests/sample.spec.ts
+47
-3
No files found.
index.ts
View file @
b7413ee6
import
'
reflect-metadata
'
;
export
*
from
'
./src/crud-base
'
;
export
*
from
'
./src/bases
'
;
export
*
from
'
./src/decorators
'
;
...
...
src/bases/id-base.ts
View file @
b7413ee6
import
{
TimeBase
}
from
'
./time-base
'
;
import
{
Generated
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryProperty
}
from
'
../utility
/query
'
;
import
{
applyQueryProperty
}
from
'
../utility
'
;
import
{
IntColumn
,
MergePropertyDecorators
,
...
...
src/bases/time-base.ts
View file @
b7413ee6
import
{
CreateDateColumn
,
DeleteDateColumn
,
UpdateDateColumn
}
from
'
typeorm
'
;
import
{
PageSettingsDto
}
from
'
../dto
/page-settings
'
;
import
{
PageSettingsDto
}
from
'
../dto
'
;
import
{
NotColumn
}
from
'
../decorators
'
;
export
interface
DeletionWise
{
...
...
@@ -36,8 +36,10 @@ export class TimeBase
return
;
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
async
prepareForSaving
():
Promise
<
void
>
{}
// eslint-disable-next-line @typescript-eslint/no-empty-function
afterSaving
()
{}
}
...
...
tests/sample.spec.ts
View file @
b7413ee6
describe
(
'
Sample test.
'
,
()
=>
{
it
(
'
should pass
'
,
()
=>
{
expect
(
true
).
toBe
(
true
);
import
{
Index
}
from
'
typeorm
'
;
import
{
plainToInstance
}
from
'
class-transformer
'
;
import
{
EnumColumn
,
IntColumn
,
StringColumn
}
from
'
../src/decorators
'
;
import
{
IdBase
}
from
'
../src/bases
'
;
import
{
validate
}
from
'
class-validator
'
;
enum
Gender
{
F
=
'
F
'
,
M
=
'
M
'
,
}
class
User
extends
IdBase
()
{
@
Index
()
@
StringColumn
(
5
,
{
required
:
true
,
})
name
:
string
;
@
IntColumn
(
'
int
'
,
{
unsigned
:
true
})
age
:
number
;
@
EnumColumn
(
Gender
)
gender
:
Gender
;
}
describe
(
'
nicot
'
,
()
=>
{
it
(
'
create entity class
'
,
()
=>
{
const
good1
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
});
const
good2
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
Gender
.
M
,
});
const
bad1
=
plainToInstance
(
User
,
{
name
:
'
John111
'
,
age
:
20
});
const
bad2
=
plainToInstance
(
User
,
{
age
:
20
});
const
bad3
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
-
1
});
const
bad4
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
'
foo
'
,
});
expect
(
validate
(
good1
)).
resolves
.
toEqual
([]);
expect
(
validate
(
good2
)).
resolves
.
toEqual
([]);
expect
(
validate
(
bad1
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad2
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad3
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad4
)).
resolves
.
not
.
toEqual
([]);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment