Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9582631
collection-item.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
collection-item.test.ts
View Options
import
assert
from
"assert"
;
import
{
App
,
Collection
,
FieldTypes
,
SuperContext
}
from
"../main"
;
import
{
withRunningApp
}
from
"../test_utils/with-test-app"
;
describe
(
"CollectionItem"
,
()
=>
{
it
(
"first inserts, then updates on successive .save() calls"
,
async
()
=>
withRunningApp
(
(
test_app
)
=>
class
extends
test_app
{
collections
=
{
...
App
.
BaseCollections
,
entries
:
new
(
class
extends
Collection
{
fields
=
{
title
:
new
FieldTypes
.
Text
()
};
})(),
};
},
async
({
app
})
=>
{
const
entry
=
await
app
.
collections
.
entries
.
suCreate
({
title
:
"title"
,
});
entry
.
set
(
"title"
,
"title2"
);
await
entry
.
save
(
new
SuperContext
(
app
));
const
{
items
:
entries
,
}
=
await
app
.
collections
.
entries
.
suList
().
fetch
();
assert
.
strictEqual
(
entries
.
length
,
1
);
assert
.
strictEqual
(
entries
[
0
].
get
(
"title"
),
"title2"
);
}
));
it
(
"first inserts, then updates on successive .save() calls (in after:create hook)"
,
async
()
=>
withRunningApp
(
(
test_app
)
=>
class
extends
test_app
{
collections
=
{
...
App
.
BaseCollections
,
entries
:
new
(
class
extends
Collection
{
fields
=
{
title
:
new
FieldTypes
.
Text
()
};
async
init
(
app
:
App
,
name
:
string
)
{
await
super
.
init
(
app
,
name
);
this
.
on
(
"after:create"
,
async
([
_
,
entry
])
=>
{
entry
.
set
(
"title"
,
"title-overwritten"
);
await
entry
.
save
(
new
SuperContext
(
app
));
});
}
})(),
};
},
async
({
app
})
=>
{
const
entry
=
await
app
.
collections
.
entries
.
suCreate
({
title
:
"title"
,
});
await
entry
.
save
(
new
SuperContext
(
app
));
const
{
items
:
entries
,
}
=
await
app
.
collections
.
entries
.
suList
().
fetch
();
assert
.
strictEqual
(
entries
.
length
,
1
);
assert
.
strictEqual
(
entries
[
0
].
get
(
"title"
),
"title-overwritten"
);
}
));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Oct 11, 07:20 (22 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
933011
Default Alt Text
collection-item.test.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment