Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
team-friendo
signalboost
Commits
6ec96fe5
Verified
Commit
6ec96fe5
authored
Sep 10, 2020
by
aguestuser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[215] ensure that destroy methods destroy associated records
parent
a0d6c4ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
app/db/repositories/channel.js
app/db/repositories/channel.js
+4
-5
app/db/repositories/phoneNumber.js
app/db/repositories/phoneNumber.js
+4
-5
test/unit/db/repositories/channel.spec.js
test/unit/db/repositories/channel.spec.js
+8
-2
No files found.
app/db/repositories/channel.js
View file @
6ec96fe5
...
...
@@ -34,11 +34,10 @@ const update = (phoneNumber, attrs) =>
// (string, Transaction | null) => Promise<boolean>
const
destroy
=
async
(
phoneNumber
,
transaction
)
=>
{
const
numDestroyed
=
await
app
.
db
.
channel
.
destroy
({
where
:
{
phoneNumber
},
...(
transaction
?
{
transaction
}
:
{}),
})
return
numDestroyed
>
0
const
channel
=
await
findByPhoneNumber
(
phoneNumber
)
return
channel
?
channel
.
destroy
({
...(
transaction
?
{
transaction
}
:
{})
}).
then
(()
=>
true
)
:
false
}
const
findAll
=
()
=>
app
.
db
.
channel
.
findAll
()
...
...
app/db/repositories/phoneNumber.js
View file @
6ec96fe5
...
...
@@ -12,11 +12,10 @@ const create = ({ phoneNumber, twilioSid, status }) =>
// (string, Transaction | null) => Promise<boolean>
const
destroy
=
async
(
phoneNumber
,
transaction
)
=>
{
const
numDestroyed
=
await
app
.
db
.
phoneNumber
.
destroy
({
where
:
{
phoneNumber
},
...(
transaction
?
{
transaction
}
:
{}),
})
return
numDestroyed
>
0
const
phoneNumberRecord
=
await
find
(
phoneNumber
)
return
phoneNumberRecord
?
phoneNumber
.
destroy
({
...(
transaction
?
{
transaction
}
:
{})
}).
then
(()
=>
true
)
:
false
}
const
find
=
phoneNumber
=>
app
.
db
.
phoneNumber
.
findOne
({
where
:
{
phoneNumber
}
})
...
...
test/unit/db/repositories/channel.spec.js
View file @
6ec96fe5
...
...
@@ -123,12 +123,18 @@ describe('channel repository', () => {
let
channel
,
channelCount
describe
(
'
when given the phone number for an existing channel
'
,
()
=>
{
beforeEach
(
async
()
=>
(
channel
=
await
db
.
channel
.
create
(
channelFactory
())))
beforeEach
(
async
()
=>
{
channel
=
await
db
.
channel
.
create
(
deepChannelFactory
(),
{
include
:
[{
model
:
db
.
membership
}],
})
})
it
(
'
deletes the instance
'
,
async
()
=>
{
it
(
'
deletes the instance
and its associations
'
,
async
()
=>
{
channelCount
=
await
db
.
channel
.
count
()
expect
(
await
channelRepository
.
destroy
(
channel
.
phoneNumber
)).
to
.
eql
(
true
)
expect
(
await
db
.
channel
.
count
()).
to
.
eql
(
channelCount
-
1
)
expect
(
await
db
.
membership
.
findOne
({
where
:
{
channelPhoneNumber
:
channel
.
phoneNumber
}
}))
.
to
.
be
.
null
})
})
...
...
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