-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from TogetherCrew/116-cascade-delete-operations
116 cascade delete operations
- Loading branch information
Showing
13 changed files
with
189 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
import { Platfrom } from '../../../src/models'; | ||
import { Platform, Community } from '../../../src/models'; | ||
import { IPlatform } from '../../../src/interfaces'; | ||
import { Types } from 'mongoose'; | ||
// import setupTestDB from '../../utils/setupTestDB'; | ||
|
||
describe('Platfrom model', () => { | ||
// setupTestDB(); | ||
|
||
describe('Platform model', () => { | ||
describe('Platform validation', () => { | ||
let platfrom: IPlatform; | ||
let platform: IPlatform; | ||
beforeEach(() => { | ||
platfrom = { | ||
platform = { | ||
name: 'Discord', | ||
community: new Types.ObjectId(), | ||
metadata: { | ||
guildId: 'guildId', | ||
selectedChannels: ['c1', 'c2'], | ||
}, | ||
disconnectedAt: null, | ||
}; | ||
}); | ||
|
||
test('should correctly validate a valid platfrom', async () => { | ||
await expect(new Platfrom(platfrom).validate()).resolves.toBeUndefined(); | ||
test('should correctly validate a valid platform', async () => { | ||
await expect(new Platform(platform).validate()).resolves.toBeUndefined(); | ||
}); | ||
|
||
// describe('Cascade deletes', () => { | ||
|
||
// test('should clean up when community is deleted', async () => { | ||
// const community = new Community({ users: [new Types.ObjectId()], name: 'community' }); | ||
// await community.save(); | ||
|
||
// const platform = new Platform({ name: 'platform', community: community._id }); | ||
// await platform.save(); | ||
|
||
// community.platforms?.push(platform._id); | ||
// await community.save(); | ||
|
||
// await platform.remove(); | ||
|
||
// const communityDoc = await Community.findById(community._id); | ||
|
||
// expect(communityDoc?.platforms).not.toContain(platform._id); | ||
|
||
// const platformDoc = await Platform.findById(platform._id); | ||
// expect(platformDoc).toBe(null); | ||
// }); | ||
// }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// import mongoose from 'mongoose'; | ||
// import config from '../../src/config'; | ||
|
||
// const setupTestDB = () => { | ||
// beforeAll(async () => { | ||
// mongoose.set('strictQuery', false); | ||
// await mongoose.connect(config.mongoose.serverURL); | ||
// }); | ||
|
||
// beforeEach(async () => { | ||
// await Promise.all( | ||
// Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({})), | ||
// ); | ||
// }); | ||
|
||
// afterAll(async () => { | ||
// await mongoose.disconnect(); | ||
// }); | ||
// }; | ||
|
||
// export default setupTestDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testPathIgnorePatterns: ['/__tests__/fixtures', '/__tests__/utils'], | ||
transform: { | ||
'^.+\\.(ts|tsx)?$': 'ts-jest', | ||
'^.+\\.(js|jsx)$': 'babel-jest', | ||
}, | ||
collectCoverage: true, | ||
testEnvironment: 'node', | ||
coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'], | ||
collectCoverageFrom: ['src/**/*.ts*'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable @typescript-eslint/restrict-template-expressions */ | ||
import Joi from 'joi'; | ||
|
||
const envVarsSchema = Joi.object() | ||
.keys({ | ||
DB_HOST: Joi.string().required().description('Mongo DB url'), | ||
DB_PORT: Joi.string().required().description('Mongo DB port'), | ||
DB_USER: Joi.string().required().description('Mongo DB username'), | ||
DB_PASSWORD: Joi.string().required().description('Mongo DB password'), | ||
DB_NAME: Joi.string().required().description('Mongo DB name'), | ||
}) | ||
.unknown(); | ||
|
||
const { value: envVars, error } = envVarsSchema.prefs({ errors: { label: 'key' } }).validate(process.env); | ||
|
||
if (error != null) { | ||
throw new Error(`Config validation error: ${error.message}`); | ||
} | ||
|
||
export default { | ||
mongoose: { | ||
serverURL: `mongodb://${envVars.DB_USER}:${envVars.DB_PASSWORD}@${envVars.DB_HOST}:${envVars.DB_PORT}/${envVars.DB_NAME}`, | ||
botURL: `mongodb://${envVars.DB_USER}:${envVars.DB_PASSWORD}@${envVars.DB_HOST}:${envVars.DB_PORT}`, | ||
dbURL: `mongodb://${envVars.DB_USER}:${envVars.DB_PASSWORD}@${envVars.DB_HOST}:${envVars.DB_PORT}`, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters