Skip to content

Commit

Permalink
Fix README regex + Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nntthuy-axonivy committed Dec 18, 2024
1 parent 8c0d85d commit 7a841a1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import static com.axonivy.market.constants.ProductJsonConstants.DEFAULT_PRODUCT_TYPE;

public class ProductContentUtils {
public static final String DEMO_SETUP_TITLE = "(?m)^## (Demo|Setup)$";
/*
* Accept any combination of #, can be ## or ###, and whitespaces before Demo/Setup word
* Match exactly Demo or Setup
*/
public static final String DEMO_SETUP_TITLE = "(?m)^[#\\s]*##?\\s*(Demo|Setup)\\s*$";
private static final String HASH = "#";
public static final String DESCRIPTION = "description";
public static final String DEMO = "demo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class BaseSetup {
protected static final String MOCK_PRODUCT_REPOSITORY_NAME = "axonivy-market/bpmn-statistic";
protected static final String MOCK_IMAGE_ID_FORMAT_1 = "imageId-66e2b14868f2f95b2f95549a";
protected static final String MOCK_IMAGE_ID_FORMAT_2 = "imageId-66e2b14868f2f95b2f95550a";
protected static final String MOCK_IMAGE_ID_FORMAT_3 = "imageId-66e2b14868f2f95b2f95551a";
protected static final String MOCK_PRODUCT_JSON_FILE_PATH = "src/test/resources/product.json";
protected static final String MOCK_PRODUCT_JSON_FILE_PATH_NO_URL = "src/test/resources/productMissingURL.json";
protected static final String MOCK_PRODUCT_JSON_WITH_DROPINS_FILE_PATH = "src/test/resources/product-dropins.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ void testReplaceImageDirWithImageCustomId() {
Map<String, String> imageUrls = new HashMap<>();
imageUrls.put("slash-command.png", MOCK_IMAGE_ID_FORMAT_1);
imageUrls.put("create-slash-command.png", MOCK_IMAGE_ID_FORMAT_2);
imageUrls.put("screen2.png", MOCK_IMAGE_ID_FORMAT_3);

String expectedResult = readmeContents.replace("images/slash-command.png",
MOCK_IMAGE_ID_FORMAT_1).replace("images/create-slash-command.png",
MOCK_IMAGE_ID_FORMAT_2);
MOCK_IMAGE_ID_FORMAT_2).replace("screen2.png \"Restful Person Manager\"", MOCK_IMAGE_ID_FORMAT_3);
String updatedContents = ProductContentUtils.replaceImageDirWithImageCustomId(imageUrls, readmeContents);

assertEquals(expectedResult, updatedContents);
Expand Down Expand Up @@ -121,7 +122,31 @@ void testGetExtractedPartsOfReadmeAtCorrectHeadings() {
assertTrue(readmeContentsModel.getDescription().startsWith("Axon Ivy’s mattermost connector"));
assertTrue(readmeContentsModel.getDemo().startsWith("### Demo sample"));
assertTrue(readmeContentsModel.getSetup().startsWith("### Setup guideline"));
}

@Test
void testGetExtractedPartsOfReadmeWithInconsistentFormats() {
String readmeContentsWithHeading3 = """
#Product-name
Test README
### Setup
Setup content (./image.png)""";
ReadmeContentsModel readmeContentsModel = ProductContentUtils.getExtractedPartsOfReadme(readmeContentsWithHeading3);
assertTrue(readmeContentsModel.getDescription().startsWith("Test README"));
assertTrue(readmeContentsModel.getSetup().startsWith("Setup content (./image.png)"));

String readmeContentsWithSpaceHeading = """
#Product-name
Test README
##Demo
### Demo project
Demo content
## Setup
Setup content (./image.png)""";
ReadmeContentsModel readmeContentsModel1 =
ProductContentUtils.getExtractedPartsOfReadme(readmeContentsWithSpaceHeading);
assertTrue(readmeContentsModel1.getDemo().startsWith("### Demo project"));
assertTrue(readmeContentsModel1.getSetup().startsWith("Setup content (./image.png)"));
}

@Test
Expand Down
1 change: 1 addition & 0 deletions marketplace-service/src/test/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This connector:
- allow you to start the Axon Ivy process by hitting the slash command key from the mattermost's channel.
- allow you to send a message to the mattermost's channel from the Axon Ivy workplace.
- notifies users on the channel for new Axon Ivy workflow Tasks.
![Restful Person Manager](screen2.png "Restful Person Manager")

## Demo

Expand Down

0 comments on commit 7a841a1

Please sign in to comment.