Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Event Bus
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Libero
Event Bus
Commits
57af8edc
Commit
57af8edc
authored
5 years ago
by
Peter Hooper
Browse files
Options
Downloads
Patches
Plain Diff
Finish testing the types
parent
39ddcff2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/event-bus/types.test.ts
+57
-10
57 additions, 10 deletions
src/event-bus/types.test.ts
with
57 additions
and
10 deletions
src/event-bus/types.test.ts
+
57
−
10
View file @
57af8edc
import
{
EventType
,
Event
}
from
'
./types
'
;
import
{
EventType
,
Event
,
EventPublisher
,
EventSubscriber
,
EventConfig
}
from
'
./types
'
;
const
expectedEventProperties
=
{
eventType
:
true
,
id
:
true
,
created
:
true
,
payload
:
true
,
version
:
false
,
context
:
false
,
};
function
createValidationFunction
<
T
>
(
properties
:
Record
<
keyof
T
,
boolean
>
):
Function
{
function
createValidationFunction
<
T
>
(
properties
:
Record
<
keyof
T
,
boolean
>
):
Function
{
return
function
<
TActual
extends
T
>
(
value
:
TActual
):
T
{
return
function
<
TActual
extends
T
>
(
value
:
TActual
):
T
{
...
@@ -42,6 +33,15 @@ describe('Event Bus Types', () => {
...
@@ -42,6 +33,15 @@ describe('Event Bus Types', () => {
});
});
it
(
'
interface Event contains expected members
'
,
()
=>
{
it
(
'
interface Event contains expected members
'
,
()
=>
{
const
expectedEventProperties
=
{
eventType
:
true
,
id
:
true
,
created
:
true
,
payload
:
true
,
version
:
false
,
context
:
false
,
};
class
ExpectedToBeAnEvent
{
class
ExpectedToBeAnEvent
{
id
=
'
234
'
;
id
=
'
234
'
;
created
:
Date
=
new
Date
();
created
:
Date
=
new
Date
();
...
@@ -51,5 +51,52 @@ describe('Event Bus Types', () => {
...
@@ -51,5 +51,52 @@ describe('Event Bus Types', () => {
const
isValidEvent
=
createValidationFunction
<
Event
<
{}
>>
(
expectedEventProperties
);
const
isValidEvent
=
createValidationFunction
<
Event
<
{}
>>
(
expectedEventProperties
);
const
ee
=
new
ExpectedToBeAnEvent
();
const
ee
=
new
ExpectedToBeAnEvent
();
expect
(()
=>
isValidEvent
(
ee
)).
not
.
toThrow
();
expect
(()
=>
isValidEvent
(
ee
)).
not
.
toThrow
();
expect
(()
=>
ee
as
Event
<
{}
>
).
not
.
toThrow
();
});
it
(
'
interface EventPublisher contains expected members
'
,
()
=>
{
const
expectedEventPublisherProperties
=
{
publish
:
true
,
};
class
ExpectedToBeAnEventPublisher
{
publish
<
T
extends
object
>
(
event
:
Event
<
T
>
):
Promise
<
boolean
>
{
return
Promise
.
resolve
(
event
!==
null
);
}
}
const
isValidEventPublisher
=
createValidationFunction
<
EventPublisher
>
(
expectedEventPublisherProperties
);
const
ep
=
new
ExpectedToBeAnEventPublisher
();
expect
(()
=>
isValidEventPublisher
(
ep
)).
not
.
toThrow
();
expect
(()
=>
ep
as
EventPublisher
).
not
.
toThrow
();
});
it
(
'
interface EventSubscriber contains expected members
'
,
()
=>
{
const
expectedEventSubscriberProperties
=
{
subscribe
:
true
,
};
class
ExpectedToBeAnEventSubscriber
{
subscribe
<
T
extends
object
>
(
eventType
:
string
,
handler
:
(
event
:
Event
<
T
>
)
=>
Promise
<
boolean
>
):
void
{
Promise
.
resolve
(
eventType
!==
''
&&
handler
!==
null
);
}
}
const
isValidEventSubscriber
=
createValidationFunction
<
EventSubscriber
>
(
expectedEventSubscriberProperties
);
const
es
=
new
ExpectedToBeAnEventSubscriber
();
expect
(()
=>
isValidEventSubscriber
(
es
)).
not
.
toThrow
();
expect
(()
=>
es
as
EventSubscriber
).
not
.
toThrow
();
});
it
(
'
interface EventConfig contains expected members
'
,
()
=>
{
const
expectedEventConfigProperties
=
{
url
:
true
,
};
class
ExpectedToBeAnEventConfig
{
url
=
'
here
'
;
}
const
isValidEventConfig
=
createValidationFunction
<
EventConfig
>
(
expectedEventConfigProperties
);
const
ep
=
new
ExpectedToBeAnEventConfig
();
expect
(()
=>
isValidEventConfig
(
ep
)).
not
.
toThrow
();
expect
(()
=>
ep
as
EventConfig
).
not
.
toThrow
();
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment