Skip to content

Commit

Permalink
fix: fixed issue where plugin wasn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
Bird87ZA committed Jan 16, 2025
1 parent d9080ec commit a524a24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface ErrorResponse {
errors: Array<ShopwareHttpError>;
}

interface StoreExtension {
name: string;
}

export default Shopware.Component.wrapComponentConfig({
template,

Expand All @@ -24,11 +28,17 @@ export default Shopware.Component.wrapComponentConfig({
inAppPurchaseCart: null as IAP.InAppPurchaseCart | null,
extension: null as IAP.Extension | null,
tosAccepted: false,
errorSnippet: null as string | null
errorSnippet: null as string | null,
storeExtension: '' as string
};
},

created() {
// @deprecated tag:v4.0.0 - Will be removed as this.store.extension will be only a string in shopware 6.7
const extension = this.store.extension as StoreExtension | string;
this.storeExtension = typeof extension === 'object' && !!extension
? extension.name
: extension;
this.createdComponent();
},

Expand Down Expand Up @@ -73,10 +83,10 @@ export default Shopware.Component.wrapComponentConfig({

await Promise.all([
this.cart = this.inAppPurchasesService.createCart(
this.store.extension.name,
this.storeExtension,
this.store.entry.identifier
),
this.inAppPurchasesService.getExtension(this.store.extension.name)
this.inAppPurchasesService.getExtension(this.storeExtension)
]).then(([inAppPurchaseCart, extension]) => {
this.inAppPurchaseCart = inAppPurchaseCart;
this.extension = extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
wrapper.vm.reset();
});

it('does not call createCart or getExtension when entry or extension not set', async () => {
const createCartSpy = jest.spyOn(wrapper.vm.inAppPurchasesService, 'createCart');
const getExtensionSpy = jest.spyOn(wrapper.vm.inAppPurchasesService, 'getExtension');

wrapper.vm.store.request(
null,
{
it('handles requestFeature method correctly', async () => {
Shopware.Context.app.config.bundles = {
jestapp: {
name: 'jestapp',
baseUrl: '',
permissions: [],
Expand All @@ -110,33 +106,9 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
integrationId: '123',
active: true
}
);
wrapper.vm.requestFeature();
expect(createCartSpy).toHaveBeenCalledTimes(0);
expect(getExtensionSpy).toHaveBeenCalledTimes(0);
wrapper.vm.store.$reset();

wrapper.vm.store.request({ featureId: 'your-feature-id' }, null);

wrapper.vm.requestFeature();
expect(createCartSpy).toHaveBeenCalledTimes(0);
expect(getExtensionSpy).toHaveBeenCalledTimes(0);
wrapper.vm.store.$reset();
wrapper.vm.reset();
});
};

it('handles requestFeature method correctly', async () => {
wrapper.vm.store.request({
featureId: 'your-feature-id'
}, {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
});
wrapper.vm.store.request({ featureId: 'your-feature-id' }, 'jestapp');
wrapper.vm.requestFeature();
expect(wrapper.vm.state).toBe('loading');

Expand All @@ -150,17 +122,18 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
Shopware.Utils.debug.error = jest.fn();

wrapper = await createWrapper(true);
wrapper.vm.store.request({
featureId: 'your-feature-id'
}, {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
});
Shopware.Context.app.config.bundles = {
jestapp: {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
}
};
wrapper.vm.store.request({ featureId: 'your-feature-id' }, 'jestapp');

wrapper.vm.requestFeature();
expect(wrapper.vm.state).toBe('loading');
Expand All @@ -174,9 +147,8 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
it('does not call orderCart when entry or extension not set', async () => {
const spy = jest.spyOn(wrapper.vm.inAppPurchasesService, 'orderCart');

wrapper.vm.store.request(
null,
{
Shopware.Context.app.config.bundles = {
jestapp: {
name: 'jestapp',
baseUrl: '',
permissions: [],
Expand All @@ -185,34 +157,30 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
integrationId: '123',
active: true
}
);

wrapper.vm.onPurchaseFeature();
expect(spy).toHaveBeenCalledTimes(0);
wrapper.vm.store.$reset();

wrapper.vm.store.request({ featureId: 'your-feature-id' }, null);
};
wrapper.vm.store.request(null, 'jestapp');

wrapper.vm.onPurchaseFeature();
expect(spy).toHaveBeenCalledTimes(0);
wrapper.vm.store.$reset();
wrapper.vm.reset();
});

it('handles onPurchaseFeature method correctly', async () => {
const spy = jest.spyOn(wrapper.vm.inAppPurchasesService, 'orderCart');

wrapper.vm.store.request({
featureId: 'your-feature-id'
}, {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
});
Shopware.Context.app.config.bundles = {
jestapp: {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
}
};

wrapper.vm.store.request({ featureId: 'your-feature-id' }, 'jestapp');
await flushPromises();

wrapper.vm.onPurchaseFeature();
Expand All @@ -229,17 +197,19 @@ describe('src/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout',
Shopware.Utils.debug.error = jest.fn();

wrapper = await createWrapper(true);
wrapper.vm.store.request({
featureId: 'your-feature-id'
}, {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
});

Shopware.Context.app.config.bundles = {
jestapp: {
name: 'jestapp',
baseUrl: '',
permissions: [],
version: '1.0.0',
type: 'app',
integrationId: '123',
active: true
}
};
wrapper.vm.store.request({ featureId: 'your-feature-id' }, 'jestapp');

wrapper.vm.onPurchaseFeature();
expect(wrapper.vm.state).toBe('loading');
Expand Down

0 comments on commit a524a24

Please sign in to comment.