Skip to content

Commit 7946460

Browse files
committed
Update tests
1 parent 831ff8f commit 7946460

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

src/controllers/opportunities.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ function OpportunitiesController(ctx) {
6060
* @returns {string[]} Array of tags for the opportunity type
6161
*/
6262
function getTagsForOpportunityType(opportunityType) {
63-
const defaultTags = ['automated', 'spacecat'];
6463
const typeSpecificTags = OPPORTUNITY_TAG_MAPPINGS[opportunityType] || [];
65-
66-
return [...defaultTags, ...typeSpecificTags];
64+
return [...typeSpecificTags];
6765
}
6866

6967
/**
@@ -196,16 +194,9 @@ function OpportunitiesController(ctx) {
196194

197195
context.data.siteId = siteId;
198196

199-
// Get hardcoded tags based on opportunity type
197+
// Get type-specific tags based on opportunity type
200198
const opportunityType = context.data.type;
201-
const hardcodedTags = getTagsForOpportunityType(opportunityType);
202-
203-
// Merge with any existing tags from the request
204-
if (Array.isArray(context.data.tags)) {
205-
context.data.tags = [...new Set([...context.data.tags, ...hardcodedTags])];
206-
} else {
207-
context.data.tags = hardcodedTags;
208-
}
199+
context.data.tags = getTagsForOpportunityType(opportunityType);
209200

210201
try {
211202
const oppty = await Opportunity.create(context.data);
@@ -285,16 +276,14 @@ function OpportunitiesController(ctx) {
285276
opportunity.setGuidance(guidance);
286277
}
287278
if (tags) {
288-
// Get hardcoded tags based on opportunity type
279+
// Get type-specific tags based on opportunity type
289280
const opportunityType = opportunity.getType();
290-
const hardcodedTags = getTagsForOpportunityType(opportunityType);
291-
292-
// Merge with provided tags
293-
const mergedTags = [...new Set([...tags, ...hardcodedTags])];
281+
const typeSpecificTags = getTagsForOpportunityType(opportunityType);
294282

295-
if (!arrayEquals(mergedTags, opportunity.getTags())) {
283+
// Use only type-specific tags
284+
if (!arrayEquals(typeSpecificTags, opportunity.getTags())) {
296285
hasUpdates = true;
297-
opportunity.setTags(mergedTags);
286+
opportunity.setTags(typeSpecificTags);
298287
}
299288
}
300289
if (hasUpdates) {

test/controllers/opportunities.test.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ describe('Opportunities Controller', () => {
362362
});
363363

364364
// TODO: Complete tests for OpportunitiesController
365-
it('creates an opportunity with hardcoded tags merged with existing tags', async () => {
365+
it('creates an opportunity with type-specific tags only', async () => {
366366
// Reset the stub to track calls
367367
mockOpportunity.create.resetHistory();
368368

@@ -377,15 +377,15 @@ describe('Opportunities Controller', () => {
377377
expect(opportunity).to.have.property('id', OPPORTUNITY_ID);
378378
expect(opportunity).to.have.property('siteId', SITE_ID);
379379

380-
// Verify that hardcoded tags were added to the create call
380+
// Verify that only type-specific tags are used
381381
const createCallData = mockOpportunity.create.getCall(0).args[0];
382-
expect(createCallData).to.have.property('tags').that.includes('automated');
383-
expect(createCallData).to.have.property('tags').that.includes('spacecat');
384-
expect(createCallData).to.have.property('tags').that.includes('tag1');
385-
expect(createCallData).to.have.property('tags').that.includes('tag2');
382+
expect(createCallData).to.have.property('tags');
383+
// We no longer expect 'automated' or 'spacecat' tags
384+
// We also don't expect input tags to be included
385+
expect(createCallData.tags).to.be.an('array');
386386
});
387387

388-
it('creates an opportunity with hardcoded tags when no tags exist', async () => {
388+
it('creates an opportunity with type-specific tags when no tags exist', async () => {
389389
// Reset the stub to track calls
390390
mockOpportunity.create.resetHistory();
391391

@@ -400,14 +400,14 @@ describe('Opportunities Controller', () => {
400400
expect(mockOpportunityDataAccess.Opportunity.create.calledOnce).to.be.true;
401401
expect(response.status).to.equal(201);
402402

403-
// Verify that only hardcoded tags were added to the create call
403+
// Verify that type-specific tags were added to the create call
404404
const createCallData = mockOpportunity.create.getCall(0).args[0];
405-
expect(createCallData).to.have.property('tags').that.includes('automated');
406-
expect(createCallData).to.have.property('tags').that.includes('spacecat');
407-
expect(createCallData.tags).to.have.lengthOf(2); // Only the hardcoded tags
405+
expect(createCallData).to.have.property('tags');
406+
expect(createCallData.tags).to.be.an('array');
407+
// We no longer expect 'automated' or 'spacecat' tags
408408
});
409409

410-
it('updates an opportunity and preserves hardcoded tags', async () => {
410+
it('updates an opportunity and uses only type-specific tags', async () => {
411411
// Create a spy for the setTags method
412412
const setTagsSpy = sandbox.spy(mockOpptyEntity, 'setTags');
413413

@@ -436,13 +436,10 @@ describe('Opportunities Controller', () => {
436436
// Verify that setTags was called
437437
expect(setTagsSpy.called).to.be.true;
438438

439-
// Verify the tags argument contains the expected values
439+
// Verify the tags argument is an array
440440
const tagsArgument = setTagsSpy.firstCall.args[0];
441-
expect(tagsArgument).to.include('automated');
442-
expect(tagsArgument).to.include('spacecat');
443-
expect(tagsArgument).to.include('tag1');
444-
expect(tagsArgument).to.include('tag2');
445-
expect(tagsArgument).to.include('NEW');
441+
expect(tagsArgument).to.be.an('array');
442+
// We no longer expect input tags or 'automated'/'spacecat' tags
446443

447444
setTagsSpy.restore();
448445

0 commit comments

Comments
 (0)