Skip to content
Merged
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
68 changes: 40 additions & 28 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "switcher-api",
"version": "1.4.0",
"version": "1.4.1",
"description": "Feature Flag/Toggle API",
"main": "src/start.js",
"type": "module",
Expand Down Expand Up @@ -41,7 +41,7 @@
"cors": "^2.8.5",
"express": "^5.1.0",
"express-basic-auth": "^1.2.1",
"express-rate-limit": "^7.5.1",
"express-rate-limit": "^8.0.1",
"express-validator": "^7.2.1",
"graphql": "^16.11.0",
"graphql-http": "^1.22.4",
Expand All @@ -50,7 +50,7 @@
"jsonwebtoken": "^9.0.2",
"moment": "^2.30.1",
"mongodb": "^6.17.0",
"mongoose": "^8.16.3",
"mongoose": "^8.16.4",
"pino": "^9.7.0",
"pino-pretty": "^13.0.0",
"swagger-ui-express": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.projectKey=switcherapi_switcher-api
sonar.projectName=switcher-api
sonar.organization=switcherapi
sonar.projectVersion=1.4.0
sonar.projectVersion=1.4.1
sonar.links.homepage=https://github.com/switcherapi/switcher-api

sonar.testExecutionReportPaths=test-report.xml
Expand Down
2 changes: 1 addition & 1 deletion src/api-docs/swagger-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
title: 'Switcher API',
version: 'v1.4.0',
version: 'v1.4.1',
description: 'Switcher API is a Feature Flag API focused on toggling features over different environments and applications.',
contact: {
name: 'Roger Floriano (petruki)',
Expand Down
10 changes: 8 additions & 2 deletions src/services/gitops/push-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ async function processChangedGroup(domain, change, environment) {
const admin = { _id: domain.owner, email: ADMIN_EMAIL };
const content = change.content;
const group = await getGroupConfig({ domain: domain._id, name: change.path[0] });

const updatedActivated = new Map(group.activated);
updatedActivated.set(environment, getChangedValue(content.activated, group.activated.get(environment)));

await updateGroup(group._id, {
description: getChangedValue(content.description, group.description),
activated: new Map().set(environment, getChangedValue(content.activated, group.activated.get(environment)))
activated: updatedActivated
}, admin);
}

Expand All @@ -29,9 +32,12 @@ async function processChangedConfig(domain, change, environment) {
const admin = { _id: domain.owner, email: ADMIN_EMAIL };
const config = await getConfig({ domain: domain._id, key: change.path[1] });

const updatedActivated = new Map(config.activated);
updatedActivated.set(environment, getChangedValue(content.activated, config.activated.get(environment)));

await updateConfig(config._id, {
description: getChangedValue(content.description, config.description),
activated: new Map().set(environment, getChangedValue(content.activated, config.activated.get(environment)))
activated: updatedActivated
}, admin);

if (content.relay) {
Expand Down
64 changes: 64 additions & 0 deletions tests/gitops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,38 @@ describe('GitOps - Push Changed', () => {
expect(group.description).toBe('Changed Group Description');
});

test('GITOPS_SUITE - Should push changes - Changed Group while keeping default', async () => {
const token = generateToken('30s');

const lastUpdate = Date.now();
const req = await request(app)
.post('/gitops/v1/push')
.set('Authorization', `Bearer ${token}`)
.send({
environment: 'staging',
changes: [{
action: 'CHANGED',
diff: 'GROUP',
path: ['Group Test'],
content: {
activated: true,
description: 'Changed Group Description'
}
}]
})
.expect(200);

expect(req.body.message).toBe('Changes applied successfully');
expect(req.body.version).toBeGreaterThan(lastUpdate);

// Check if the changes were applied
const group = await GroupConfig.findOne({ name: 'Group Test', domain: domainId }).lean().exec();
expect(group).not.toBeNull();
expect(group.activated['staging']).toBe(true);
expect(group.activated[EnvType.DEFAULT]).toBeDefined();
expect(group.description).toBe('Changed Group Description');
});

test('GITOPS_SUITE - Should push changes - Changed Switcher', async () => {
const token = generateToken('30s');

Expand Down Expand Up @@ -460,6 +492,38 @@ describe('GitOps - Push Changed', () => {
expect(config.description).toBe('Changed Switcher Description');
});

test('GITOPS_SUITE - Should push changes - Changed Switcher while keeping default', async () => {
const token = generateToken('30s');

const lastUpdate = Date.now();
const req = await request(app)
.post('/gitops/v1/push')
.set('Authorization', `Bearer ${token}`)
.send({
environment: 'staging',
changes: [{
action: 'CHANGED',
diff: 'CONFIG',
path: ['Group Test', 'TEST_CONFIG_KEY'],
content: {
activated: true,
description: 'Changed Switcher Description'
}
}]
})
.expect(200);

expect(req.body.message).toBe('Changes applied successfully');
expect(req.body.version).toBeGreaterThan(lastUpdate);

// Check if the changes were applied
const config = await Config.findOne({ key: 'TEST_CONFIG_KEY', domain: domainId }).lean().exec();
expect(config).not.toBeNull();
expect(config.activated['staging']).toBe(true);
expect(config.activated[EnvType.DEFAULT]).toBeDefined();
expect(config.description).toBe('Changed Switcher Description');
});

test('GITOPS_SUITE - Should push changes - Changed Switcher Relay (added)', async () => {
const token = generateToken('30s');

Expand Down