Skip to content
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

Feat/strapi filters #37

Merged
merged 13 commits into from
Aug 23, 2023
Merged
75 changes: 37 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,6 @@

### 🏠 [Homepage](README.md)

## An Appeal
## Medusa-Strapi: Embrace the Power of Empathy in Content Management! 🚀

Hey there, Supporter! 👋

Welcome to the world of Medusa-Strapi, the perfect companion to the MedusaJS e-commerce framework! As we set out to make a lasting impact in the digital realm, we invite you to join our journey and experience the magic of empathetic content management.

Medusa-Strapi is not just any content management system; it's a heartfelt project that empowers creators and businesses to thrive alongside the MedusaJS e-commerce framework. Together, we're on a mission to simplify content management while embracing the principles of empathy and collaboration.

### Why We Need Your Help:

Through Medusa-Strapi, we've already witnessed the profound impact it's had on countless lives. Businesses can now craft compelling stories with ease, while developers find joy in building seamless experiences. Together, we've saved valuable hours, giving individuals the freedom to focus on what truly matters.

### You Can Make a Difference:

Your support, no matter the size - whether it's a generous $5 or a magnificent $10 - fuels our quest. With your backing, we can:

- **Empower Dreams:** Behind every line of code lies a dream - the dream of a developer leaving an indelible mark, a small business flourishing, or a content creator inspiring the world. Your support brings these dreams to life, turning them into awe-inspiring realities.

- **Craft Simplicity:** We believe in technology that empowers, not complicates. Your kindness helps us build an intuitive content management system, allowing businesses to effortlessly create and manage content.

- **Celebrate Humanity:** Medusa-Strapi is not just software; it's a vibrant community driven by empathy. Your support strengthens these bonds, fostering a space where ideas flourish, and hearts unite.

### Join Our Journey:

Be a part of Medusa-Strapi's story and the FOSS movement. 🌟 Embrace the spirit of openness, collaboration, and shared growth. Together, let's empower this journey, making an indelible impact on countless lives.

[![GitHub Sponsors](https://img.shields.io/github/sponsors/SGFGOV/medusa-strapi-repo?label=Sponsor%20Medusa-Strapi&style=social)](https://github.com/sponsors/SGFGOV)

Ready to join the ranks of change-makers? 🚀 Pledge your support or learn more at [github.com/SGFGOV/medusa-strapi-repo](https://github.com/SGFGOV/medusa-strapi-repo).

Embrace the power of empathy in Medusa-Strapi's journey today! 💫

With heartfelt gratitude,

Govind
Medusa-Strapi Team 🤝


## Introduction
Expand Down Expand Up @@ -97,7 +60,9 @@ We support strapi v4.10.5 at the moment with medusa version.

## Install

This is the easiest bit
This is the easiest

#### NOTE: Please don't use create strapi-app, there will be too many configuration changes

1. Clone the repo.
2. Go to the medusa-strapi folder inside <yourrepo>/packages/medusa-strapi
Expand Down Expand Up @@ -144,3 +109,37 @@ Give a ⭐️ if this project helped you! Catch me on discord @govdiw
As you might have guessed by now that considerable time and effort has gone into make this product useful to the community at large, and I'd love to keep maintaining and upgrading this. However, As much as we love FOSS software, nothing in this world is truly free. Please help by [sponsoring or supporting the project]. (https://github.com/sponsors/SGFGOV)

***
## An Appeal
## Medusa-Strapi: Embrace the Power of Empathy in Content Management! 🚀

Hey there, Supporter! 👋

Welcome to the world of Medusa-Strapi, the perfect companion to the MedusaJS e-commerce framework! As we set out to make a lasting impact in the digital realm, we invite you to join our journey and experience the magic of empathetic content management.

Medusa-Strapi is not just any content management system; it's a heartfelt project that empowers creators and businesses to thrive alongside the MedusaJS e-commerce framework. Together, we're on a mission to simplify content management while embracing the principles of empathy and collaboration.

### Why We Need Your Help:

Through Medusa-Strapi, we've already witnessed the profound impact it's had on countless lives. Businesses can now craft compelling stories with ease, while developers find joy in building seamless experiences. Together, we've saved valuable hours, giving individuals the freedom to focus on what truly matters.

### You Can Make a Difference:

Your support, no matter the size - whether it's a generous $5 or a magnificent $10 - fuels our quest. With your backing, we can:

- **Empower Dreams:** Behind every line of code lies a dream - the dream of a developer leaving an indelible mark, a small business flourishing, or a content creator inspiring the world. Your support brings these dreams to life, turning them into awe-inspiring realities.

- **Craft Simplicity:** We believe in technology that empowers, not complicates. Your kindness helps us build an intuitive content management system, allowing businesses to effortlessly create and manage content.

- **Celebrate Humanity:** Medusa-Strapi is not just software; it's a vibrant community driven by empathy. Your support strengthens these bonds, fostering a space where ideas flourish, and hearts unite.

### Join Our Journey:

Be a part of Medusa-Strapi's story and the FOSS movement. 🌟 Embrace the spirit of openness, collaboration, and shared growth. Together, let's empower this journey, making an indelible impact on countless lives.

[![GitHub Sponsors](https://img.shields.io/github/sponsors/SGFGOV/medusa-strapi-repo?label=Sponsor%20Medusa-Strapi&style=social)](https://github.com/sponsors/SGFGOV)


With heartfelt gratitude,

SGFGOV
Medusa-Strapi Team 🤝
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
"**/class-validator": "^0.14.0",
"**/engine.io": "^6.4.2",
"**/strapi-plugin-multi-country-select": "npm:@sgftech/plugin-multi-country-select",
"**/typescript": "4.9.5"
"**/typescript": "4.9.5",
"**/codemirror": "5.65.11",
"**/protobufjs":"^7.2.4",
"**/tough-cookie":"^4.1.3",
"**/node-fetch":"^2.6.7",
"**/follow-redirects":"^1.14.8",
"**/axios":"0.27.2",
"**/@strapi/utils":"4.12.5",
"**/semver":"^7.5.2"

}
}
2 changes: 1 addition & 1 deletion packages/medusa-plugin-strapi-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"@medusajs/medusa": "^1.8.2",
"@strapi/plugin-users-permissions": "^4.6.1",
"@types/express": "^4.17.14",
"@types/express": "^4.17.17",
"@types/jest": "^27.4.0",
"@types/jsonwebtoken": "^9.0.0",
"@types/node": "^18.11.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Request, Response } from 'express';
import { GetFromStrapiParams, AuthInterface } from '../../../types/globals';
import UpdateStrapiService from '../../../services/update-strapi';
import { ConfigModule } from '@medusajs/medusa/dist/types/global';

export default async (req: Request, res: Response) => {
const updateStrapiService = req.scope.resolve('updateStrapiService') as UpdateStrapiService;
Expand All @@ -16,11 +15,15 @@ export default async (req: Request, res: Response) => {

const strapiEntityType = req.params.type;
const id = req.params.id;
const urlParams = req.params;
const urlQuery = req.query;

const strapiParams: GetFromStrapiParams = {
authInterface,
strapiEntityType: strapiEntityType,
id,
urlParams,
urlQuery,
};

const data = await updateStrapiService.getEntitiesFromStrapi(strapiParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default (app, options, config: ConfigModule) => {
contentRouter.options('/:type',cors(config.projectConfig.store_cors));*/
}
contentRouter.use(utils);
/*app.set('query parser', (queryString) => {
return new URLSearchParams(queryString);
});*/
contentRouter.get('/:type/:id', fetchContent);
contentRouter.get('/:type', fetchContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import UpdateStrapiService, { StrapiResult } from '../update-strapi';
import logger from '../__mocks__/logger';
import axios, { AxiosError } from 'axios';
import exp from 'constants';
import qs from 'qs';

// This sets the mock adapter on the default instance

Expand Down Expand Up @@ -122,7 +123,7 @@ describe('StrapiService Tests', () => {
'fields[0]=title&pagination[pageSize]=10&pagination[page]=1&' +
'publicationState=live&locale[0]=en';

const query = service._createStrapiRestQuery({
const query = service.createStrapiRestQuery({
sort: ['title:asc'],
filters: {
title: {
Expand All @@ -140,6 +141,12 @@ describe('StrapiService Tests', () => {
});
expect(query).toBe(testQueryPattern);
});
describe('test user parameter parsing', () => {
it('test parameter creation', () => {
const string = service.appendIdToStrapiFilter('', 'medusa_1235');
expect(string).toMatch(`medusa_1235`);
});
});
});
describe('user CURD', () => {
it(
Expand Down Expand Up @@ -219,8 +226,8 @@ describe('StrapiService Tests', () => {
it(
'register or login default medusa user',
async () => {
const creds = await service.registerOrLoginDefaultMedusaUser();
expect(creds.token).toBeDefined();
const credentials = await service.registerOrLoginDefaultMedusaUser();
expect(credentials.token).toBeDefined();
},
testTimeOut
);
Expand All @@ -230,8 +237,8 @@ describe('StrapiService Tests', () => {
async () => {
if (!isMockEnabled()) {
await service.deleteDefaultMedusaUser();
const creds = await service.loginAsDefaultMedusaUser();
expect(creds).toBeUndefined();
const credentials = await service.loginAsDefaultMedusaUser();
expect(credentials).toBeUndefined();
} else {
console.warn('disabled when not connected to test server');
expect(true).toBe(true);
Expand Down Expand Up @@ -333,8 +340,29 @@ describe('StrapiService Tests', () => {
});
expect(productGetResult).toBeDefined();
expect(productGetResult.data.length > 0).toBeTruthy();
const productFieldsGetResult = await service.getEntitiesFromStrapi({
authInterface: defaultAuthInterface,
strapiEntityType: 'products',
urlQuery: { fields: ['title', 'id', 'medusa_id'] },
});
expect(productFieldsGetResult.data[0].id).toBeDefined();
expect(productFieldsGetResult.data[0].medusa_id).toBeDefined();
if (!isMockEnabled()) {
expect(productFieldsGetResult.data[0].title).toBeDefined();
}
expect(productFieldsGetResult.data[0].handle).toBeUndefined();
const productPopulateGetResult = await service.getEntitiesFromStrapi({
authInterface: defaultAuthInterface,
strapiEntityType: 'products',
urlQuery: { populate: 'product-variants' },
});
if (!isMockEnabled()) {
const testData = productPopulateGetResult.data[0];
expect(testData['product-variants']).toBeDefined();
}
}
},

testTimeOut
);

Expand Down Expand Up @@ -488,10 +516,10 @@ describe('StrapiService Tests', () => {
expect(result.status == 200 || result.status == 302).toBeTruthy();

/* expect(result.data).toMatchObject({
id: expect.any(Number),
data: { title: expect.any(String) },
medus_id: expect.any(String)
});*/
id: expect.any(Number),
data: { title: expect.any(String) },
medus_id: expect.any(String)
});*/

if (result) {
const productVariantGetResult = await service.getEntitiesFromStrapi({
Expand All @@ -510,10 +538,10 @@ describe('StrapiService Tests', () => {
expect(result.status == 200 || result.status == 302).toBeTruthy();

/* expect(result.data).toMatchObject({
id: expect.any(Number),
data: { title: "test-product-variant-2" },
medus_id: expect.any(String)
});*/
id: expect.any(Number),
data: { title: "test-product-variant-2" },
medus_id: expect.any(String)
});*/
expect(spy).toHaveBeenCalled();
});
it('create and update product category in strapi', async () => {
Expand All @@ -522,10 +550,10 @@ describe('StrapiService Tests', () => {
expect(result.status == 200 || result.status == 302).toBeTruthy();

/* expect(result.data).toMatchObject({
id: expect.any(Number),
data: { title: expect.any(String) },
medus_id: expect.any(String)
});*/
id: expect.any(Number),
data: { title: expect.any(String) },
medus_id: expect.any(String)
});*/

if (result) {
const productCategoryResult = await service.getEntitiesFromStrapi({
Expand All @@ -544,10 +572,10 @@ describe('StrapiService Tests', () => {
expect(result.status == 200 || result.status == 302).toBeTruthy();

/* expect(result.data).toMatchObject({
id: expect.any(Number),
data: { title: "test-product-variant-2" },
medus_id: expect.any(String)
});*/
id: expect.any(Number),
data: { title: "test-product-variant-2" },
medus_id: expect.any(String)
});*/
expect(spy).toHaveBeenCalled();
});
});
Expand All @@ -564,10 +592,9 @@ describe('StrapiService Tests', () => {
const falseResult = await service.getEntitiesFromStrapi({
strapiEntityType: 'product-variants',
authInterface: defaultAuthInterface,
id: result.data?.medusa_id,
id: IdMap.getId('exists'),
});
expect(falseResult.status).toBe(200);
//expect(falseResult.data?.length).toBe(0);
expect(falseResult.status).toBe(404);
} else {
console.warn('disabled when not connected to test server');
expect(true).toBe(true);
Expand All @@ -585,11 +612,11 @@ describe('StrapiService Tests', () => {
});

/* result = await service.deleteCollectionInStrapi(
{ id: "exists" },
defaultAuthInterface
);
{ id: "exists" },
defaultAuthInterface
);

expect(result.status != 200).toBeTruthy();*/
expect(result.status != 200).toBeTruthy();*/

result = await service.deleteProductMetafieldInStrapi(
{ id: IdMap.getId('exists') },
Expand Down Expand Up @@ -632,8 +659,7 @@ describe('StrapiService Tests', () => {
authInterface: defaultAuthInterface,
id: result.data?.medusa_id,
});
expect(falseResult.status).toBe(200);
expect(falseResult.data?.length).toBe(0);
expect(falseResult.status).toBe(404);

result = await service.deleteProductTypeInStrapi({ id: 'dummy' }, defaultAuthInterface);
expect(result.status).toBe(200);
Expand All @@ -643,9 +669,7 @@ describe('StrapiService Tests', () => {
id: result.data?.medusa_id,
});

expect(falseResult.status).toBe(200);
expect(falseResult.data?.length).toBe(0);
expect(falseResult.data?.length).toBe(0);
expect(falseResult.status).toBe(404);
result = await service.deleteCollectionInStrapi(
{ id: IdMap.getId('exists') },
defaultAuthInterface
Expand Down Expand Up @@ -691,8 +715,8 @@ describe('region checks', () => {
authInterface: defaultAuthInterface,
id: result.data?.deletedData.medusa_id,
});
expect(falseResult.status != 200).toBeTruthy();
// expect(falseResult.data?.data.length).toBe(0);
expect(falseResult.status == 404).toBeTruthy();

await service.deleteDefaultMedusaUser();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import StrapiService from '../update-strapi';
import { jest, describe, expect, beforeEach, it, beforeAll, afterAll } from '@jest/globals';
import jwt from 'jsonwebtoken';
import supertest from 'supertest';
import qs from 'qs';
import {
regionService,
productService,
Expand Down Expand Up @@ -263,6 +264,32 @@ describe('StrapiService Tests', () => {
timeOut
);

it(
'GET any /content/products?=query',
async () => {
const query = qs.stringify({
fields: ['id', 'handle', 'medusa_id'],
filters: {
medusa_id: IdMap.getId('exists'),
},
populate: '*',
});
const result = await supertest(app)
.get(`/strapi/content/products?${query}`)
.set('Accept', 'application/json')
.expect(200);

expect(result?.body).toBeDefined();
expect(result?.body.error).toBeUndefined();
if (!isMockEnabled()) {
expect(result.body.data[0].medusa_id).toBe(IdMap.getId('exists'));
}
// Check the response type and length
// Check the response data
},
timeOut
);

/**
it("POST hooks/seed", async () => {
const strapiSignal: StrapiSignal = {
Expand Down
Loading
Loading