-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Add new field platformTarget (#189)
- Loading branch information
1 parent
7d26b08
commit b648ca7
Showing
20 changed files
with
389 additions
and
8 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
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,59 @@ | ||
import SimpleSchema from "simpl-schema"; | ||
import { throwMeteorError } from "../error"; | ||
import { PlatformTargets, platformTargetsSchema } from "../collections"; | ||
import { AppLogger } from "../logger"; | ||
import { rateLimiter } from "./rate-limiting"; | ||
import { VeritasValidatedMethod, Admin } from "./role"; | ||
|
||
const checkUniquePlatformTargetName = async (platformTarget) => { | ||
if (await PlatformTargets.find({ name: platformTarget.name }).countAsync() > 0) { | ||
throwMeteorError("name", "Nom de la plateforme cible existe déjà !"); | ||
} | ||
}; | ||
|
||
const insertPlatformTarget = new VeritasValidatedMethod({ | ||
name: "insertPlatformTarget", | ||
role: Admin, | ||
async validate(newPlatformTarget) { | ||
await checkUniquePlatformTargetName(newPlatformTarget); | ||
platformTargetsSchema.validate(newPlatformTarget); | ||
}, | ||
async run(newPlatformTarget) { | ||
let platformTargetDocument = { | ||
name: newPlatformTarget.name, | ||
}; | ||
|
||
let newPlatformTargetId = await PlatformTargets.insertAsync(platformTargetDocument); | ||
let newPlatformTargetAfterInsert = await PlatformTargets.findOneAsync({ _id: newPlatformTargetId }); | ||
|
||
AppLogger.getLog().info( | ||
`Insert platformTarget ID ${newPlatformTargetId}`, | ||
{ before: "", after: newPlatformTargetAfterInsert }, | ||
this.userId | ||
); | ||
|
||
return newPlatformTargetAfterInsert; | ||
}, | ||
}); | ||
|
||
const removePlatformTarget = new VeritasValidatedMethod({ | ||
name: "removePlatformTarget", | ||
role: Admin, | ||
validate: new SimpleSchema({ | ||
platformTargetId: { type: String }, | ||
}).validator(), | ||
async run({ platformTargetId }) { | ||
let platformTarget = await PlatformTargets.findOneAsync({ _id: platformTargetId }); | ||
await PlatformTargets.removeAsync({ _id: platformTargetId }); | ||
|
||
AppLogger.getLog().info( | ||
`Delete platformTarget ID ${platformTargetId}`, | ||
{ before: platformTarget, after: "" }, | ||
this.userId | ||
); | ||
}, | ||
}); | ||
|
||
rateLimiter([insertPlatformTarget, removePlatformTarget]); | ||
|
||
export { insertPlatformTarget, removePlatformTarget }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import assert from "assert"; | ||
import { PlatformTargets } from "../../collections"; | ||
import { insertPlatformTarget, removePlatformTarget } from "../platform-target"; | ||
import { createUser } from "../../../../tests/helpers"; | ||
import { loadFixtures } from "../../../../server/fixtures"; | ||
import { resetDatabase } from "../../../../server/fixtures-test"; | ||
|
||
if (Meteor.isServer) { | ||
describe("meteor methods platformTarget", function () { | ||
before(async function () { | ||
await resetDatabase(); | ||
await loadFixtures(); | ||
}); | ||
|
||
it("insert platformTarget", async () => { | ||
let userId = await createUser(); | ||
|
||
const context = { userId }; | ||
const args = { | ||
name: "openshift-4" | ||
}; | ||
|
||
await insertPlatformTarget._execute(context, args); | ||
|
||
let nb = await PlatformTargets.find({}).countAsync(); | ||
let platformTarget = await PlatformTargets.findOneAsync({ name: "openshift-4" }); | ||
|
||
assert.strictEqual(nb, 1); | ||
assert.strictEqual(platformTarget.name, "openshift-4"); | ||
}); | ||
|
||
it("remove platformTarget", async () => { | ||
let userId = await createUser(); | ||
let platformTarget = await PlatformTargets.findOneAsync({ name: "openshift-4" }); | ||
|
||
const context = { userId }; | ||
const args = { platformTargetId: platformTarget._id }; | ||
|
||
let nbBefore = await PlatformTargets.find({}).countAsync(); | ||
assert.strictEqual(nbBefore, 1); | ||
|
||
await removePlatformTarget._execute(context, args); | ||
|
||
let nbAfter = await PlatformTargets.find({}).countAsync(); | ||
assert.strictEqual(nbAfter, 0); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.