Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Permet au SUPER ADMIN de mettre à jour la colonne params sur les fonctionnalités (PIX-16763) #11531

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ async function saveInBatch(organizationFeatures) {
try {
const knexConn = DomainTransaction.getConnection();
await knexConn('organization-features')
.insert(organizationFeatures)
.insert(
organizationFeatures.map((organizationFeature) => ({
...organizationFeature,
params: JSON.stringify(organizationFeature.params),
})),
)
.onConflict(['featureId', 'organizationId'])
.ignore();
.merge();
} catch (err) {
if (knexUtils.foreignKeyConstraintViolated(err) && err.constraint.includes('featureid')) {
throw new FeatureNotFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@ describe('Integration | Repository | Organization-for-admin', function () {
expect(result[1].params).to.deep.equal(organizationFeatures[1].params);
});

it('should update existing rows', async function () {
// given
const otherOrganization = databaseBuilder.factory.buildOrganization();
databaseBuilder.factory.buildOrganizationFeature({
featureId: feature.id,
organizationId: organization.id,
params: `{ "id": 0 }`,
});
await databaseBuilder.commit();

const organizationFeatures = [
new OrganizationFeature({
featureId: feature.id,
organizationId: organization.id,
params: `["SOMETHING"]`,
}),
new OrganizationFeature({
featureId: feature.id,
organizationId: otherOrganization.id,
params: `{ "id": 456 }`,
}),
];

// when
await organizationFeatureRepository.saveInBatch(organizationFeatures);

//then
const result = await knex('organization-features').where({
featureId: feature.id,
});

expect(result).to.have.lengthOf(2);
expect(result[0].featureId).to.deep.equal(organizationFeatures[0].featureId);
expect(result[0].organizationId).to.deep.equal(organizationFeatures[0].organizationId);
expect(result[0].params).to.deep.equal(organizationFeatures[0].params);
expect(result[1].featureId).to.deep.equal(organizationFeatures[1].featureId);
expect(result[1].organizationId).to.deep.equal(organizationFeatures[1].organizationId);
expect(result[1].params).to.deep.equal(organizationFeatures[1].params);
});

it('should passe even if organization feature already exists', async function () {
databaseBuilder.factory.buildOrganizationFeature({ organizationId: organization.id, featureId: feature.id });
await databaseBuilder.commit();
Expand Down