-
Notifications
You must be signed in to change notification settings - Fork 12
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
780 refactor shift the logic for checking win condition #876
Merged
pmarsh-scottlogic
merged 11 commits into
dev
from
780-refactor-shift-the-logic-for-checking-win-condition
Mar 25, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f102268
moves checkLevelWinCondition to its own file
pmarsh-scottlogic 5056a62
change email models to types rather than interfaces
pmarsh-scottlogic dd37c2e
remove everything about wonLevel from the chat call chain
pmarsh-scottlogic a96a71b
adapt win condition to take severl emails
pmarsh-scottlogic c2c186c
check win condition i nchat controller
pmarsh-scottlogic e8ecee8
adapt email tests to winCondition tests
pmarsh-scottlogic bb66aa6
fix existing chatController tests
pmarsh-scottlogic bae1131
adds frame for testing for win condition in chatController
pmarsh-scottlogic c94435d
fill in those tests
pmarsh-scottlogic e35d211
remove console debug
pmarsh-scottlogic 9f539f6
renames to isLevelWon
pmarsh-scottlogic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 +1,14 @@ | ||
import { EmailInfo } from './models/email'; | ||
import { LEVEL_NAMES } from './models/level'; | ||
|
||
function sendEmail( | ||
address: string, | ||
subject: string, | ||
body: string, | ||
confirmed: boolean, | ||
// default to sandbox | ||
currentLevel: LEVEL_NAMES = LEVEL_NAMES.SANDBOX | ||
confirmed: boolean | ||
) { | ||
if (!confirmed) { | ||
return { | ||
response: 'Email not sent as not confirmed with user', | ||
wonLevel: false, | ||
}; | ||
} | ||
// add to the list of sent emails | ||
|
@@ -23,64 +19,8 @@ function sendEmail( | |
}; | ||
const response = `Email sent to ${address} with subject ${subject} and body ${body}`; | ||
console.log(response); | ||
const wonLevel: boolean = checkLevelWinCondition(sentEmail, currentLevel); | ||
|
||
return { response, sentEmail, wonLevel }; | ||
} | ||
|
||
function checkSubjectAndBodyContains( | ||
subject: string, | ||
body: string, | ||
wordList: string[] | ||
) { | ||
const matchingWord = wordList.find((word) => { | ||
return ( | ||
subject.toLowerCase().includes(word.toLowerCase()) || | ||
body.toLowerCase().includes(word.toLowerCase()) | ||
); | ||
}); | ||
return !!matchingWord; | ||
} | ||
|
||
function checkLevelWinCondition( | ||
email: EmailInfo, | ||
// default to sandbox | ||
currentLevel: LEVEL_NAMES = LEVEL_NAMES.SANDBOX | ||
) { | ||
switch (currentLevel) { | ||
case LEVEL_NAMES.LEVEL_1: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct fruit name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['brae']) | ||
); | ||
case LEVEL_NAMES.LEVEL_2: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct project name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['pearl']) | ||
); | ||
case LEVEL_NAMES.LEVEL_3: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct lake name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['verity']) && | ||
// correct water usage in different formats | ||
checkSubjectAndBodyContains(email.subject, email.body, [ | ||
'20 million', | ||
'20million', | ||
'twenty million', | ||
'20000000', | ||
'20,000,000', | ||
'20.000.000', | ||
]) | ||
); | ||
default: | ||
return false; | ||
} | ||
return { response, sentEmail }; | ||
} | ||
|
||
export { sendEmail }; |
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,13 +1,12 @@ | ||
interface EmailInfo { | ||
type EmailInfo = { | ||
address: string; | ||
subject: string; | ||
body: string; | ||
} | ||
}; | ||
|
||
interface EmailResponse { | ||
type EmailResponse = { | ||
response: string; | ||
sentEmail?: EmailInfo; | ||
wonLevel: boolean; | ||
} | ||
}; | ||
|
||
export type { EmailInfo, EmailResponse }; |
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,64 @@ | ||
import { EmailInfo } from './models/email'; | ||
import { LEVEL_NAMES } from './models/level'; | ||
|
||
function checkSubjectAndBodyContains( | ||
subject: string, | ||
body: string, | ||
wordList: string[] | ||
) { | ||
const matchingWord = wordList.find((word) => { | ||
return ( | ||
subject.toLowerCase().includes(word.toLowerCase()) || | ||
body.toLowerCase().includes(word.toLowerCase()) | ||
); | ||
}); | ||
return !!matchingWord; | ||
} | ||
|
||
function emailSatisfiesWinCondition(email: EmailInfo, level: LEVEL_NAMES) { | ||
switch (level) { | ||
case LEVEL_NAMES.LEVEL_1: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct fruit name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['brae']) | ||
); | ||
case LEVEL_NAMES.LEVEL_2: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct project name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['pearl']) | ||
); | ||
case LEVEL_NAMES.LEVEL_3: | ||
return ( | ||
// correct email address | ||
email.address.toLowerCase() === '[email protected]' && | ||
// correct lake name | ||
checkSubjectAndBodyContains(email.subject, email.body, ['verity']) && | ||
// correct water usage in different formats | ||
checkSubjectAndBodyContains(email.subject, email.body, [ | ||
'20 million', | ||
'20million', | ||
'twenty million', | ||
'20000000', | ||
'20,000,000', | ||
'20.000.000', | ||
]) | ||
); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
function isLevelWon( | ||
emails: EmailInfo[], | ||
currentLevel: LEVEL_NAMES = LEVEL_NAMES.SANDBOX | ||
) { | ||
return emails.some((email) => | ||
emailSatisfiesWinCondition(email, currentLevel) | ||
); | ||
} | ||
|
||
export { isLevelWon }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how many places this has been removed from 🥳