Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Fix sharing from posts on userpage #953

Merged
merged 7 commits into from
Jun 13, 2024
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
8 changes: 4 additions & 4 deletions docs/METRICS_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
## Metrics Report
In this document, we are reporting the results of the additional metrics we have chosen for DHBWhub.

### Coupling
### Relation among classes
We have used the tool [ck](https://github.com/mauricioaniche/ck) to calculate metrics such as the depth of the inheritance tree, number of children, method inheritance factor and response for class. These are the results:



### Web Application Performance
### Web Application Performance and Monitoring
We have used the web extension 'PageSpeed Insights' to evaluate our website in regards to its rendering and response performance. The following image contains the result for the current state of our application:

![grafik](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/926b8fe6-249c-4f37-8ab8-a33762f730e6)

The high score on best practices is just what we wanted to achieve with our component based architecture on the frontend. The low score on the response time was quite expected, since there are several reasons for it:
1. On the homepage, all the posts are retrieved from the database every time you enter it or refresh the tab. The reason is to provide consistent data which is conform to the data in the database.
2. Our backend is located on a BWcloud server which was provided for free for every student in the region. Thus, there are obviously restrictions regarding the request and response times between the backend and the frontend.

### Web Application Monitoring
25 changes: 19 additions & 6 deletions docs/TEST_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ In the backend, we are planning to check for each function, whether they are tra
### 4. Test Cases
All the tests that are depicted in the next subtopics have already passed, since we only launch new features to our main branch, whenever all the relevant tests have passed.
#### 4.1 Frontend
> TODO
We have decided to only test the service classes automatically in the frontend. One reason for this is that we prioritized, that the requested data is mapped and transformed into the right data model. Moreover, when testing new functions in the frontend, we already use the whole application via node.js, which reacts just like what our actual website would react like. Thus, we can prove our new functions by testing out manually on the actual frontend on our own branch, before pushing it to the main branch.
One example for an automated test on the frontend looks like this:

![FrontendTest](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/69a1521e-1502-4429-89f6-cbbbabae9df7)

Hereby, we are mocking the eventhandler with jest, and test whether a new editable tag appears on the post editor, after a valid one has been entered by the user.

#### 4.2 Backend
Each layer in the backend consists of similar test structures. Thus, we will show you an example for each layer, that is applicable for all the other entity models in our project.
#### Controller
Expand All @@ -51,23 +57,30 @@ Basically the same as the tests in the service layer, since the repositories use

### 5. Test Results
#### Frontend
> Todo

In the following image, you can see all the test regarding the DescriptionService class running at the same time.

![SingleTest](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/50969957-8fa3-4c3a-85fb-bba9ca503a72)

#### Backend
In the following image, you can see an example of running all the tests related to the AccountController at the same time. JUnit shows whether each test has passed and if yes, how long did it take.

![RunAllTests](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/da3354e6-5230-4d76-999c-a9a6b4865480)

### 6. Metrics
#### Frontend
> Todo
In the following image, you can see all the test suites run at once.

![RunAllTests](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/df0ac362-6b32-4131-ab41-1720eda34c1c)

#### Backend
When building the local version of the project that contains the newly implemented feature, Maven automatically runs all the tests that are located in the test package. The same applies to creating pull requests in which a maven pipeline does the same function and tells all the developers, whether all the tests in the branch function correctly:

![MavenBuild](https://github.com/SE-TINF22B6/DHBWhub/assets/122597204/01b72b92-ab64-4632-add9-03d2c699ca94)

### 7. Recommendations
Although our current tests can verify that components function properly under certain conditions, it is still important to use our actual product as much as possible. The largest amount of bugs and errors can be found through actual interaction with the website and imitation of an actual client user. Stress tests can also be helpful to determine, whether our database and backend connection is strong enough to handle multiple requests at the same time while also maintaining data coherence.

### 8. Conclusion
> This section summarizes the key findings of the testing and the overall status of the software quality.
> TODO towards the end
- Automated backend tests are definitily easier to make, since we only regard the correct transformation of the data.
- On the frontend however, automated tests are only partly necessary. Manual testing is more important and easier to execute.
- There are some factors, that can't be tested automatically like stable network connections or response latency when retrieving lots of data back to back from the database or backend.
11 changes: 6 additions & 5 deletions src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ public Post create(PostProposal proposal) {
public HomepagePostPreviewProposal create(CreatePostProposal proposal) {
// Creating the Post itself
User user = userRepository.findByAccountId(proposal.getAccountId());
if(user == null){
if (user == null) {
throw new NoSuchEntryException("User with the AccountId " + proposal.getAccountId() + " does not exist!");
}
Picture picture = !proposal.getPostImage().isEmpty() ?
pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())): null;

Post post = repository.save(PostMapper.mapToModel(proposal,user,picture));
Picture picture = proposal.getPostImage() != null ?
pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())) : null;

Post post = repository.save(PostMapper.mapToModel(proposal, user, picture));

// Creating Tags after the Post is created
Arrays.stream(proposal.getTags()).forEach(t -> {
PostTag postTag = new PostTag(post, t);
postTagRepository.save(postTag);
} );
});

return getPostHomepageView(post.getId());
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/web/src/scenes/User/UserPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const UserPost: React.FC<PostModel> = (props: PostModel) => {
const [comments] = useState(commentAmount);
const [menuOpen, setMenuOpen] = useState(false);
const [shareWindowOpen, setShareWindowOpen] = useState(false);
const currentPageURL: string = window.location.href;
const location = useLocation();
const [shortDescription, setShortDescription] = useState('');
const searchParams: URLSearchParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -247,7 +246,7 @@ export const UserPost: React.FC<PostModel> = (props: PostModel) => {
)}
{shareWindowOpen && (
<div className="post-share-container">
<Share postId={id} currentPageURL={currentPageURL}></Share>
<Share postId={id} currentPageURL={process.env.PUBLIC_URL +"/post/?id="+id}></Share>
</div>
)}
{reportOpen && (
Expand Down
Loading