-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for sharing product from app (containing text and short URL)
- Loading branch information
1 parent
6563f29
commit 9d2ae15
Showing
14 changed files
with
151 additions
and
99 deletions.
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
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
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,7 +1,9 @@ | ||
package ru.ekuzmichev | ||
package product | ||
|
||
import zio.{ULayer, ZLayer} | ||
import util.ozon.OzonShortUrlResolver | ||
|
||
import zio.{RLayer, ZLayer} | ||
|
||
object ProductIdParserLayers: | ||
val ozon: ULayer[ProductIdParser] = ZLayer.succeed(new OzonProductIdParser) | ||
val ozon: RLayer[OzonShortUrlResolver, ProductIdParser] = ZLayer.fromFunction(new OzonProductIdParser(_)) |
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,7 +1,8 @@ | ||
package ru.ekuzmichev | ||
package util.ozon | ||
|
||
import io.lemonlabs.uri.Url | ||
import zio.Task | ||
|
||
trait OzonShortUrlResolver: | ||
def resolveShortUrl(url: String): Task[String] | ||
def resolveShortUrl(url: Url): Task[Url] |
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 was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
src/test/scala/product/OzonProductIdParserIntegrationTest.scala
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,94 @@ | ||
package ru.ekuzmichev | ||
package product | ||
|
||
import util.ozon.OzonShortUrlResolverImpl | ||
|
||
import net.ruippeixotog.scalascraper.browser.JsoupBrowser | ||
import zio.test.* | ||
import zio.test.Assertion.* | ||
|
||
object OzonProductIdParserIntegrationTest extends ZIOSpecDefault: | ||
def spec: Spec[Any, Throwable] = | ||
suite("OzonProductIdParser.parse")( | ||
test("parse Ozon product id from Ozon URL 'shared' from browser") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse( | ||
"https://www.ozon.ru/product/kanistra-dlya-smeshivaniya-benzina-i-masla-dde-2-l-1422144661/?__rr=1&from=share_ios&utm_campaign=productpage_link&utm_medium=share_button&utm_source=smm" | ||
) | ||
.map { parseResult => | ||
assert(parseResult)(isRight(equalTo("kanistra-dlya-smeshivaniya-benzina-i-masla-dde-2-l-1422144661"))) | ||
} | ||
}, | ||
test("parse take product id from plain non-URL string") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse( | ||
"akusticheskaya-gitara-donner-hush-i-silent-guitar-sunburst-6-strunnaya-988766503" | ||
) | ||
.map { parseResult => | ||
assert(parseResult)( | ||
isRight(equalTo("akusticheskaya-gitara-donner-hush-i-silent-guitar-sunburst-6-strunnaya-988766503")) | ||
) | ||
} | ||
}, | ||
test("parse Ozon product id from Ozon link URL without query parameters") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse( | ||
"https://www.ozon.ru/product/kanistra-dlya-smeshivaniya-benzina-i-masla-dde-2-l-1422144661" | ||
) | ||
.map { parseResult => | ||
assert(parseResult)(isRight(equalTo("kanistra-dlya-smeshivaniya-benzina-i-masla-dde-2-l-1422144661"))) | ||
} | ||
}, | ||
test("parse Ozon product id from Ozon short URL") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse("https://ozon.ru/t/YKknAE4") | ||
.map { parseResult => | ||
assert(parseResult)( | ||
isRight( | ||
equalTo( | ||
"kovrik-samonaduvayushchiysya-naturehike-yugu-ultralight-automatic-inflatable-cushion-mummy-blue-b-r-1449496528" | ||
) | ||
) | ||
) | ||
} | ||
}, | ||
test("parse Ozon product id from Ozon short URL wrapped with text") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse( | ||
"Коврик Самонадувающийся Naturehike Yugu Ultralight Automatic Inflatable Cushion Mummy Blue (Б/Р) https://ozon.ru/t/YKknAE4" | ||
) | ||
.map { parseResult => | ||
assert(parseResult)( | ||
isRight( | ||
equalTo( | ||
"kovrik-samonaduvayushchiysya-naturehike-yugu-ultralight-automatic-inflatable-cushion-mummy-blue-b-r-1449496528" | ||
) | ||
) | ||
) | ||
} | ||
}, | ||
test("fail if link has no path") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse("https://www.ozon.ru/product/") | ||
.map { parseResult => | ||
assert(parseResult)(isLeft) | ||
} | ||
}, | ||
test("fail if link has invalid host") { | ||
val parser = makeProductIdParser | ||
parser | ||
.parse("https://www.vk.ru/product/kanistra-dlya-smeshivaniya-benzina-i-masla-dde-2-l-1422144661") | ||
.map { parseResult => | ||
assert(parseResult)(isLeft) | ||
} | ||
} | ||
) | ||
|
||
private def makeProductIdParser: ProductIdParser = | ||
new OzonProductIdParser(new OzonShortUrlResolverImpl(new JsoupBrowser())) |
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
src/test/scala/util/ozon/OzonShortUrlResolverImplTestApp.scala
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 was deleted.
Oops, something went wrong.
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